This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
/*
* author: robosapien
* created: 2020-11-09 23:46:27
*/
#include<bits/stdc++.h>
using namespace std;
#define bs ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define ll long long int
#define pb push_back
#define all(x) x.begin(),x.end()
#define ff first
#define ss second
#define pii pair<int,int>
void solve(){
int n;
cin >> n;
int a[n] = {};
for(int i = 0; i < n - 1; ++i) cin >> a[i];
int pos_pref = 0, neg_pref = 0, mx_pref = INT_MIN, mn_pref = INT_MAX;
for(int i = 0; i < n - 1; ++i) {
if(a[i] > 0)
pos_pref += a[i], neg_pref = 0;
if(a[i] < 0)
neg_pref += a[i], pos_pref = 0;
mx_pref = max(pos_pref, mx_pref);
mn_pref = min(neg_pref, mn_pref);
}
if(mn_pref == -n + 1 || mx_pref == n - 1) {
int fi = 1;
int pref = 0;
for(int i = 0; i < n - 1; ++i) {
pref += a[i];
fi = max(fi, 1 - pref);
}
vector<int> ans(n);
pref = 0;
if(fi < 1) {
cout << -1;
return;
}
for(int i = 0; i < n; ++i) {
if(fi + pref < 1 or fi + pref > n) {
cout << -1;
return;
}
ans[i] = (fi + pref);
pref += a[i];
}
for(int i = 0; i < n; ++i)
cout << ans[i] << " ";
} else {
cout << -1;
}
}
int main()
{
bs;
int t = 1;
// cin >> t;
while(t--){
solve();
}
#ifdef LOCAL_DEFINE
cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
}
# | 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... |