Source Code
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define sz(s)    (int)(s.size())
#define endl "\n"
#define PI acos(-1)
#define all(a) a.begin(), a.end()

void Open() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);
#endif  !ONLINEJUDGE
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
}
int dx[]{ 1, -1, 0, 0, 1, 1, -1, -1 };
int dy[]{ 0, 0, 1, -1, 1, -1, 1, -1 };
const int OO = 0x3f3f3f3f;

int main()
{
   // Open();

    int n;
    cin >> n;
    vector < int > v(n);
    for (auto& e : v)cin >> e;
    

    vector < ll > ans;
    ll sum = v[0];

    for (int i = 1; i < n; i++) {
        if (sum + v[i] <= sum) {
            sum += v[i];
        }
        else {
            ans.push_back(sum);
            sum = v[i];
        }
    }
    ans.push_back(sum);
    for (auto e : ans)cout << e << " ";


}
Copy
b hossam
GNU G++17
0 ms
580 KB
Wrong Answer