fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define int long long int
  4. #define double long double
  5. #define print(a) for(auto x : a) cout << x << " "; cout << endl
  6. inline int power(int a, int b) {
  7. int x = 1;
  8. while (b) {
  9. if (b & 1) x *= a;
  10. a *= a;
  11. b >>= 1;
  12. }
  13. return x;
  14. }
  15.  
  16.  
  17. const int M = 1000000007;
  18. const int N = 3e5+9;
  19. const int INF = 2e9+1;
  20. const int LINF = 2000000000000000001;
  21.  
  22. //_ ***************************** START Below *******************************
  23.  
  24.  
  25. bool isPossible(int n, int m, int k, int mid){
  26.  
  27. int sum = (mid*(mid+1)/2) * 2;
  28.  
  29.  
  30. int left = mid - k;
  31. if(left<0){
  32. sum += abs(left);
  33. left = 0;
  34. }
  35.  
  36. int right = mid - (n-k) - 1;
  37. if(right<0){
  38. sum += abs(right);
  39. right = 0;
  40. }
  41.  
  42. sum -= (left*(left+1)/2 + right*(right+1)/2 + mid);
  43.  
  44. return sum<=m;
  45.  
  46. }
  47.  
  48. void consistency(int n, int m, int k){
  49.  
  50. int s = 1, e = INF;
  51.  
  52. while(s<e){
  53. int mid = s + (e-s+1)/2;
  54. if(isPossible(n, m, k, mid)){
  55. s = mid;
  56. }
  57. else e = mid-1;;
  58. }
  59.  
  60. cout << e << endl;
  61.  
  62. }
  63.  
  64. void solve() {
  65.  
  66. int n, m, k;
  67. cin>>n >> m >> k;
  68.  
  69. consistency(n, m, k);
  70.  
  71.  
  72. }
  73.  
  74.  
  75.  
  76.  
  77.  
  78. int32_t main() {
  79. ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  80.  
  81. int t = 1;
  82. cin >> t;
  83. while (t--) {
  84. solve();
  85. }
  86.  
  87. return 0;
  88. }
Success #stdin #stdout 0.01s 5280KB
stdin
1
5 11 3
stdout
3