Source Code
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vl;
#define all(v) v.begin(), v.end()
#define pb push_back    
#define sz(x) (int)(x).size()
const int N = 3e5 + 5;
void solve() {
    int n;
    scanf("%d", &n);
    vl a(n + 1), del(n + 1);
    for(int i = 0; i < n; ++i)
        scanf("%lld", &a[i]);
    ll c = 0;
    for(int i = n - 1; i > 0; --i) {
        if(a[i] <= 0) {
            a[i - 1] += a[i];
            del[i] = 1;
        }
    }
    for(int i = 0; i < n; ++i){
        if(!del[i])
            printf("%lld ", a[i]);
    }
}
int main() {
    int t = 1;
    // scanf("%d",&t);
    while(t--)
        solve();
}
Copy
b Kamoon
GNU G++17
37 ms
7.0 MB
Wrong Answer