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-1] > a[i]) {
            a[i]=a[i-1]+a[i];
        }
        else {
            v.push_back(a[i-1]);
        }
    }
    v.push_back(a[n-1]);
    for (auto x : v) printf("%d ",x);
    cout << endl;
}
Copy
b MOohamed_Mahfouz
GNU G++17
0 ms
600 KB
Wrong Answer