#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector<int>d(n - 1);
int x = 1e6, diff = 0;
for(int i = 0; i < n - 1; i++) {
cin >> d[i];
diff += d[i];
x = min(x, diff);
}
if(x < 0) x = abs(x) + 1;
vector<int>a(n);
int curVal = x;
a[0] = x;
bool f = false;
for(int i = 1; i < n; i++) {
curVal += d[i - 1];
a[i] = curVal;
if(a[i] > n || a[i] < 1) {
f = true;
break;
}
}
if((n == 2 && x == 0) || f) {
cout << -1;
return 0;
}
for(int i = 0; i < n; i++) {
cout << a[i] << " ";
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
52 ms |
4692 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
60 ms |
4680 KB |
Output is correct |
4 |
Correct |
32 ms |
2640 KB |
Output is correct |
5 |
Incorrect |
58 ms |
4176 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |