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;
  28.  
  29. int left = mid - k;
  30. if(left<0) left = 0;
  31.  
  32. int right = mid - (n-k) - 1;
  33. if(right<0) right = 0;
  34.  
  35. int jobs = sum - left*(left+1)/2 + sum - right*(right+1)/2 - mid;
  36.  
  37. return jobs<=m;
  38.  
  39. }
  40.  
  41. void consistency(int n, int m, int k){
  42.  
  43. int s = n/m, e = INF;
  44.  
  45. while(s<e){
  46. int mid = s + (e-s+1)/2;
  47. if(isPossible(n, m, k, mid)){
  48. s = mid;
  49. }
  50. else e = mid-1;;
  51. }
  52.  
  53. cout << e << endl;
  54.  
  55. }
  56.  
  57. void solve() {
  58.  
  59. int n, m, k;
  60. cin>>n >> m >> k;
  61.  
  62. consistency(n, m, k);
  63.  
  64.  
  65. }
  66.  
  67.  
  68.  
  69.  
  70.  
  71. int32_t main() {
  72. ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  73.  
  74. int t = 1;
  75. cin >> t;
  76. while (t--) {
  77. solve();
  78. }
  79.  
  80. return 0;
  81. }
Success #stdin #stdout 0.01s 5320KB
stdin
1
5 11 3
stdout
3