#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define ll long long
#define all(x) (x).begin(), (x).end()
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n;
cin >> n;
int d[n - 1];
int add = 1, sum = 1;
for (int i = 0; i < n - 1; i++) {
cin >> d[i];
sum += d[i];
if (sum < 0) {
add += abs(sum);
sum = 0;
}
if (sum > n) {
cout << -1 << endl;
return 0;
}
}
vector<int> ans(n);
ans[0] = add;
for (int i = 0; i < n - 1; i++) ans[i + 1] = ans[i] + d[i];
for (int i = 0; i < n; i++) {
if (ans[i] < 0 || ans[i] > n) {
cout << -1;
return 0;
}
}
add++;
vector<int> newAns(n);
newAns[0] = add;
for (int i = 0; i < n - 1; i++) newAns[i + 1] = newAns[i] + d[i];
for (int i = 0; i < n; i++) {
if (newAns[i] < 0 || newAns[i] > n) {
for (int i = 0; i < n; i++) cout << ans[i] << " ";
return 0;
}
}
cout << -1;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
29 ms |
5724 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Incorrect |
14 ms |
3932 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |