Source Code
#include<iostream>
#include<math.h>
#include<string.h>
#include<algorithm>
#include<climits>
#include<vector>
long gcd(long n,long m)
{
	while(n!=m)
	{
		if(n>m)
			n-=m;
		else
			m-=n;
	}
	return n;
}
using namespace std;
int main() {
int n;
cin>>n;
vector<long>a,b;
for(int i=0;i<n;i++)
{
	long v;
	cin>>v;
	a.push_back(v);
}
b.push_back(a.back());
for(int i=n-2;i>=0;i--)
{
	if(b.back()<0)
	{
		b.back()=b.back()+a[i];
	}
	else
	{
		b.push_back(a[i]);
	}
}
int k=b.size();
for(int i=k-1;i>=0;i--)
	cout<<b[i]<<" ";
	return 0;
}
Copy
b sameh58
GNU G++17
1 ms
256 KB
Wrong Answer