This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define MAXN (1000005)
int main() {
ios_base::sync_with_stdio(false);cin.tie(0);
ll N;
cin>>N;
ll D[N - 1];
for(ll i = 0;i < N - 1;i++){
cin>>D[i];
}
ll arr[N];
memset(arr,0,sizeof(0));
ll minimum = 1;
ll maximum = N;
ll prefixsum = 0;
for(ll i = 0;i < N - 1;i++){
prefixsum += D[i];
if(prefixsum <= 0){
minimum = max(minimum,-1 * prefixsum + 1);
}
if(prefixsum >= 0){
maximum = min(maximum,N - prefixsum);
}
}
if(minimum < 1 || maximum > N || minimum > maximum || maximum - minimum >= 1){
cout<<-1<<'\n';
}else{
arr[0] = maximum;
for(ll i = 1;i < N;i++){
arr[i] = arr[i - 1] + D[i - 1];
}
for(ll i = 0;i < N;i++){
cout<<arr[i]<<" ";
}
cout<<'\n';
}
}
# | 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... |