Source Code
//in the name of Allah

#include<bits/stdc++.h>

#define ll long long
#define pb push_back
#define mp make_pair
#define fr first
#define sc second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define SPEED ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define sz size()
#define all(x) x.begin(),x.end()
#define OO 1e16
#define R return
#define Test int TT;cin>>TT;for(int T=1;T<=TT;T++)

using namespace std;
const ll N = 200010,Mod = 1e9 + 7;
ll n,m,a[N];
string s;


int main()
{
    SPEED;
    cin >> n;
    for(int i=0; i<n; i++)
    {
        cin >> a[i];
    }
    vector<int> x;
    ll Sum = a[n-1];
    for(int i=n-2; i>=0; i--)
    {
        if(Sum > 0)
        {
            x.pb(Sum);
            Sum = a[i];
        }
        else
        {
            Sum += a[i];

        }
        if(i == 0)
            x.pb(Sum);
    }
    reverse(all(x));
    for(int i=0; i<x.sz; i++)
    {
        cout << x[i] << " ";
    }
    cout << endl;

    R 0;
}
Copy
b yaman_alwaza
GNU G++17
0 ms
700 KB
Wrong Answer