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;
int main()
{
ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
int n;
cin >> n;
int a[n] = {};
int pref = 0, mx_pref = INT_MIN;
for(int i = 0; i < n - 1; ++i) {
cin >> a[i];
pref += a[i];
mx_pref = max(mx_pref, pref);
}
if(mx_pref != n - 1) {
cout << -1;
}
else {
int first = n;
pref = 0;
for(int i = 0; i < n - 1; ++i) {
pref += a[i];
first = min(first, max(1, 1 - pref));
}
pref = 0;
vector<int> ans(n);
bool ok = true;
for(int i = 0; i < n; ++i) {
ans.push_back(first + pref);
pref += a[i];
if(first + pref < 1 or first + pref > n)
ok = false;
}
if(ok){
for(int i = 0; i < n; ++i)
cout << ans[i] << " ";
}
else {
cout << -1;
}
}
}
# | 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... |