#include<stdio.h>
#include<stdlib.h>
#include<iostream>
using namespace std;
int main()
{
int N;
cin >> N;
int *in=(int*)malloc(sizeof(int)*(N-1)), *out = (int*)malloc(sizeof(int) * (N));
int neg_max=0, pos_max=0, sum=0,possible=0,oneindex=-1,posindex=-1,negindex=-1;
for (int a = 0; a < N - 1; a++)
{
cin >> in[a];
sum += in[a];
if (neg_max > sum) {
neg_max = sum;
negindex = a;
}
if (pos_max < sum) {
pos_max = sum;
posindex = a;
}
if (pos_max - neg_max > N - 1)
{
possible = 0;
break;
}
if (pos_max - neg_max == N - 1)
{
oneindex = negindex + 1;
possible = 1;
}
}
if (possible == 0)
cout << -1;
else {
out[oneindex] = 1;
for (int a = oneindex - 1; a >= 0; a--)
out[a] = out[a + 1] - in[a];
for (int a = oneindex + 1; a < N; a++)
out[a] = out[a - 1] + in[a - 1];
for (int a = 0; a < N; a++)
cout << out[a] << " ";
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |