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

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

    scanf("%d",&n);
    for (int i=0;i<n;i++) {
        scanf("%d",&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) printf("%d ",x);
        }
    }
    else
        for (auto x : v) printf("%d ",x);
}
Copy
b MOohamed_Mahfouz
GNU G++17
0 ms
596 KB
Wrong Answer