Submission

Status:

----------

Subtask/Task Score:

0/100

Score: 0

User: nicekrittaphat

Problemset: ปริมาตรน้ำท่วม

Language: cpp

Time: 0.004 second

Submitted On: 2026-10-13 20:49:19

#include<iostream>
#include<cmath>
using namespace std;

int findlayer(int num){
    int n=0;
    while(pow(2*n+1,2)<num){
        n+=1;
    }
return n;
}

int main(){
    int n;
    cin>>n;
    int layer = findlayer(n);
    int topright = pow((2*layer+1),2)-(2*layer);
    if(topright<=n){
        cout<<topright;
    }
    else{
        if(n<topright-2){
            layer-=1;
            topright = pow((2*layer+1),2)-(2*layer);
            cout<<topright;
        }
        else
        cout<<"Cannot find top-right corner.";
    }


}