Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int n,m,k;
- int solve(int a){
- int t=m;
- t-=a-1;
- t-=n;
- if(t<0)return -1;
- int r=0;
- if(a>k-2)r=k-1;
- else r=a;
- int ar=a-(r-1);
- t-=((a+ar)/2)*n;
- if(t<0)return -1;
- if(a>(n-k))r=(n-k);
- else r=a;
- ar=a-(r-1);
- t-=((a+ar)/2)*n;
- if(t<0)return -1;
- if(t==0)return 0;
- else return 1;
- }
- int main()
- {
- cin>>n>>m>>k;
- int l=1,r=1000000009;
- while(l>r){
- int s=(l+r)/2;
- int res=solve(s);
- if(res==-1)r=m-1;
- else if(res==0)l=m;
- else l=m+1;
- }
- cout<<l;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement