Source Code
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast","unroll-loops")
#define ll long long
#define endl '\n'
#define vct vector<int>
#define pii pair<int,int>
#define pb push_back
using namespace std;
void solve(){
    ll n;
    cin>>n;
    int a[n+2];
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    a[n]=a[n-1]+1;
    // vector<int>ans;
    for(int i=0;i<n;i++){
        if(a[i]>a[i+1]){
            int o = a[i],ind=1;
            while(o>a[i+ind]){
                o+=a[i+ind];
                ind++;
                // cout<<a[i]+a[i+1]<<" ";
                // i++;
            }
            cout<<o<<" ";
            i+=ind-1;
        }
        else{
            cout<<a[i]<<" ";
        }
    }
}
int main(){
    // ios_base::sync_with_stdio(0);
    // cin.tie(0);
    ll t=1;
    // cin>>t;
    while(t--){
        solve();
    }
}
Copy
b AbdelH2O
GNU G++17
0 ms
696 KB
Wrong Answer