#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;
}
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
49 ms |
4816 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |