Advertisement
Guest User

Untitled

a guest
Jan 22nd, 2017
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.66 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int n,m,k;
  6.  
  7. int solve(int a){
  8. int t=m;
  9. t-=a-1;
  10. t-=n;
  11. if(t<0)return -1;
  12. int r=0;
  13.  
  14. if(a>k-2)r=k-1;
  15. else r=a;
  16.  
  17. int ar=a-(r-1);
  18.  
  19. t-=((a+ar)/2)*n;
  20. if(t<0)return -1;
  21.  
  22. if(a>(n-k))r=(n-k);
  23. else r=a;
  24.  
  25. ar=a-(r-1);
  26.  
  27. t-=((a+ar)/2)*n;
  28. if(t<0)return -1;
  29.  
  30. if(t==0)return 0;
  31. else return 1;
  32.  
  33. }
  34. int main()
  35. {
  36. cin>>n>>m>>k;
  37.  
  38. int l=1,r=1000000009;
  39.  
  40. while(l>r){
  41. int s=(l+r)/2;
  42. int res=solve(s);
  43. if(res==-1)r=m-1;
  44. else if(res==0)l=m;
  45. else l=m+1;
  46. }
  47.  
  48. cout<<l;
  49.  
  50. return 0;
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement