Source Code
#include <bits/stdc++.h>

using namespace std;
long long n,a[300001];
vector <long long> v;
int main()
{

    cin >> n;
    for (int i=0;i<n;i++) {
        cin >> a[i];
    }
    for (int i=1;i<n;i++) {
        if (a[i] < a[i-1]) {
            a[i]+=a[i-1];
        }
        else {
            v.push_back(a[i-1]);
        }
    }
    v.push_back(a[n-1]);
    if (v.size() > 1) {
        if (v[v.size()-2] > v[v.size()-1]) {
            long long sum = 0;
            for (auto x : v) sum+=x;
            cout << sum ;
        }
        else {
            for (auto x : v) cout << x << ' ';
        }
    }
    else
        for (auto x : v) cout << x <<  ' ';
    cout << endl;
}
Copy
b MOohamed_Mahfouz
GNU G++14
0 ms
712 KB
Wrong Answer