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() {
int n;
cin >> n;
vector<int> nums(n);
for (int i = 1; i < n; i++) {
cin >> nums[i];
}
vector<int> ps(n);
for (int i = 1; i < n; i++) {
ps[i] = ps[i-1]+nums[i];
}
auto it = max_element(ps.begin(), ps.end());
int x = *min_element(ps.begin(), ps.end());
if (*it-x != n-1) {
cout << "-1\n";
return 0;
}
vector<int> ans(n);
int idx = it-ps.begin();
ans[idx] = n;
for (int i = idx+1; i < n; i++) {
ans[i] = ans[i-1]+nums[i];
}
for (int i = idx-1; i >= 0; i--) {
ans[i] = ans[i+1]-nums[i+1];
}
for (int i = 0; i < n; i++) {
cout << ans[i] << ' ';
}
cout << '\n';
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... |