Advertisement
pb_jiang

CF1898B

Aug 2nd, 2024
263
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.30 KB | None | 0 0
  1. // Problem: B. Milena and Admirer
  2. // Contest: Codeforces - Codeforces Round 910 (Div. 2)
  3. // URL: https://codeforces.com/problemset/problem/1898/B
  4. // Memory Limit: 256 MB
  5. // Time Limit: 1000 ms
  6. //
  7. // Powered by CP Editor (https://cpeditor.org)
  8.  
  9. #include <assert.h>
  10. #include <bits/stdc++.h>
  11. using namespace std;
  12. #ifndef __DEBUG__
  13. #define dbg(...) 42
  14. #endif
  15. template <class T> using mpq = priority_queue<T, vector<T>, greater<T>>;
  16.  
  17. using ll = long long;
  18. using pii = pair<int, int>;
  19. using pll = pair<ll, ll>;
  20. using vl = vector<ll>;
  21. using vi = vector<int>;
  22.  
  23. void solve1()
  24. {
  25.     ll n;
  26.     cin >> n;
  27.     vl a(n);
  28.     for (auto &x : a)
  29.         cin >> x;
  30.     reverse(a.begin(), a.end());
  31.     ll op = 0;
  32.     for (ll i = 0, prev = a[0]; i < n; ++i) {
  33.         if (a[i] > prev) {
  34.             if (a[i] % prev == 0) {
  35.                 op += a[i] / prev - 1;
  36.             } else {
  37.                 if (a[i] >= 2 * prev - 1) {
  38.                     if (i == n - 1) {
  39.                         op += (a[i] + prev - 1) / prev - 1;
  40.                     } else {
  41.                         op += (a[i] + prev - a[i] % prev) / prev - 1;
  42.                         prev = prev - 1;
  43.                     }
  44.                 } else {
  45.                     op += 1;
  46.                     prev = a[i] / 2;
  47.                 }
  48.             }
  49.         } else {
  50.             prev = a[i];
  51.         }
  52.     }
  53.     cout << op << '\n';
  54. }
  55.  
  56. void solve2()
  57. {
  58.     ll n;
  59.     cin >> n;
  60.     vl a(n);
  61.     for (auto &x : a)
  62.         cin >> x;
  63.     reverse(a.begin(), a.end());
  64.     ll op = 0;
  65.     for (ll i = 0, prev = a[0]; i < n; ++i) {
  66.         if (a[i] <= prev) {
  67.             a[i] = prev;
  68.         } else {
  69.             ll t = (a[i] + prev - 1) / prev;
  70.             prev = a[i] / t;
  71.             op += t - 1;
  72.         }
  73.     }
  74.     cout << op << '\n';
  75. }
  76.  
  77. void solve()
  78. {
  79.     ll n;
  80.     cin >> n;
  81.     vl a(n);
  82.     for (auto &x : a)
  83.         cin >> x;
  84.     reverse(a.begin(), a.end());
  85.     ll op = 0;
  86.     for (ll i = 0; i + 1 < n; ++i) {
  87.         if (a[i] < a[i + 1]) {
  88.             ll y = ((a[i + 1] + a[i] - 1) / a[i]);
  89.             a[i + 1] = a[i + 1] / y;
  90.             op += y - 1;
  91.         }
  92.     }
  93.     cout << op << '\n';
  94. }
  95.  
  96. int main(int argc, char **argv)
  97. {
  98.     ll t;
  99.     cin >> t;
  100.     while (t--) {
  101.         solve();
  102.     }
  103.     return 0;
  104. };
  105.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement