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