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;
#define fi first
#define se second
#define ld long double
#define all(x) x.begin(),x.end()
#define sz(x) (int)x.size()
#define dbg if(0)
#define BUG(x) dbg cerr << (#x) << " is " << (x) << endl
const int mxn = (int)3e5+5;
void solve(){
int n; cin>>n;
vector<int>a(n), d(n-1);
for(auto &x:d)cin>>x;
a[0]=1;
int mn = a[0];
for(int i=0; i<n-1; i++){
a[i+1]=a[i]+d[i];
mn = min(mn,a[i+1]);
}
int diff = 1-mn;
mn = n+1; int mx=0;
for(int i=0; i<n; i++){
a[i]+=diff;
if(a[i]>n){
cout<<-1<<"\n";
return;
}
mn = min(mn,a[i]);
mx = max(mx,a[i]);
}
if(mn!=1||mx!=n){
cout<<-1<<"\n";
return;
}
for(int i=0; i<n; i++)
cout<<a[i]<<" \n"[i==n-1];
}
int main(){
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
// int t=1; cin>>t; while(t--)
solve();
return 0;
}
# | 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... |