Advertisement
Josif_tepe

Untitled

Feb 27th, 2022
1,050
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.62 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4. #include <queue>
  5. using namespace std;
  6.  
  7. int main() {
  8.     int n;
  9.     cin >> n;
  10.     vector<int> a(n);
  11.     for(int i = 0; i < n; i++) {
  12.         cin >> a[i];
  13.     }
  14.     int L = 0, R = n - 1;
  15.     int ans = 0;
  16.     while(L <= R) {
  17.         if(a[L] < a[R]) {
  18.             L++;
  19.             a[L] += a[L - 1];
  20.             ans++;
  21.         }
  22.         else if(a[L] > a[R]) {
  23.             R--;
  24.             a[R] += a[R + 1];
  25.             ans++;
  26.         }
  27.         else {
  28.             L++;
  29.             R--;
  30.         }
  31.     }
  32.     cout << ans << endl;
  33.    
  34.     return 0;
  35. }
  36.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement