fork download
  1. #include <bits/stdc++.h>
  2. #include<iostream>
  3. #include<bitset>
  4. #include<unordered_set>
  5. #include<algorithm>
  6. using namespace std;
  7. #define int long long
  8. #define ld long double
  9. #define ull unsigned long long
  10. #define endl '\n'
  11. #define pb push_back
  12. #define pf push_front
  13. #define sz(s) (int)(s.size())
  14. #define all(v) v.begin(),v.end()
  15. #define allr(v) v.rbegin(),v.rend()
  16. #define pq priority_queue
  17. #define mp make_pair
  18. #define S second
  19. #define F first
  20. #define cin(v) for(auto &it:v)cin>>it;
  21. #define cinG(grid) for(auto &r:grid) for(auto &c:r)cin>>c;
  22. #define cout(v) for(auto &it:v)cout<<it<<" ";
  23. #define ret return
  24. typedef vector<int> vi;
  25. typedef vector<vi> vvi;
  26. typedef vector<bool> vb;
  27. typedef vector<vb> vvb;
  28. typedef vector<char> vc;
  29. typedef vector<vc> vvc;
  30. typedef vector<pair<int, int>> vpi;
  31.  
  32. int Inf = 2e18;
  33. int num;
  34. const int mod = 1e9 + 7;
  35. //solve
  36.  
  37.  
  38. const int N = 2e3 + 5;
  39. int di[8]{ 1 , -1 , 0 , 0 , 1 , 1 , -1 , -1 };
  40. int dj[8]{ 0 , 0 , 1 , -1 , 1 , -1 , -1 , 1 };
  41. char dv[4]{ 'D','U','R','L' };
  42.  
  43.  
  44.  
  45. int can(int addCandiesTimes, int n, int rc) {
  46. int totallC = addCandiesTimes * (addCandiesTimes + 1) / 2;
  47. int ateTimes = totallC - rc;
  48. ret ateTimes;
  49. }
  50.  
  51.  
  52. void Zero() {
  53. int n, rc; cin >> n >> rc;
  54. int l = 0, r = n;
  55. int ans = 0;
  56. while (l <= r) {
  57. int addCTimes = l + ((r - l) >> 1);
  58. int ateTimes = can(addCTimes, n, rc);
  59. if (ateTimes + addCTimes == n) {
  60. ans = ateTimes;
  61. break;
  62. }
  63. else if (ateTimes + addCTimes < n) {
  64. l = addCTimes + 1;
  65. }
  66. else {
  67. r = addCTimes - 1;
  68. }
  69. }
  70.  
  71. cout << ans << endl;
  72.  
  73. }
  74.  
  75. void solve() {
  76. int tc = 1;
  77.  
  78. //put pre processing functions here
  79.  
  80.  
  81. //cin >> tc;
  82. while (tc--) {
  83. Zero();
  84. }
  85. }
  86.  
  87. signed main() {
  88. // ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr); // Not needed with scanf/printf
  89. solve();
  90. return 0;
  91. }
Success #stdin #stdout 0.01s 5296KB
stdin
Standard input is empty
stdout
0