Ankit_132

B

Nov 19th, 2023
554
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.68 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. #define ll     long long
  6. #define _test   int _TEST; cin>>_TEST; while(_TEST--)
  7.  
  8. int main()
  9. {
  10.     _test
  11.     {
  12.         int n;
  13.         cin>>n;
  14.        
  15.         vector<ll> a(n);
  16.        
  17.         for(int i=0; i<n; i++)
  18.             cin >> a[i];
  19.        
  20.         ll prev = INT_MAX;
  21.         ll ans = 0;
  22.        
  23.         for(int i=n-1; i>=0; i--)
  24.         {
  25.             if(a[i] <= prev)
  26.                 prev = a[i];
  27.             else
  28.             {
  29.                 ll sa = (a[i] + prev - 1) / prev;
  30.                 ans += sa - 1;
  31.                 prev = a[i] / sa;
  32.             }
  33.         }
  34.        
  35.         cout<<ans<<"\n";
  36.     }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment