Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <algorithm>
- #include <queue>
- using namespace std;
- int main() {
- int n;
- cin >> n;
- vector<int> a(n);
- for(int i = 0; i < n; i++) {
- cin >> a[i];
- }
- int L = 0, R = n - 1;
- int ans = 0;
- while(L <= R) {
- if(a[L] < a[R]) {
- L++;
- a[L] += a[L - 1];
- ans++;
- }
- else if(a[L] > a[R]) {
- R--;
- a[R] += a[R + 1];
- ans++;
- }
- else {
- L++;
- R--;
- }
- }
- cout << ans << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement