#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
vector<int> a(n - 1);
for (int i = 0; i < n - 1; i++) {
cin >> a[i];
}
int sum = 0;
vector<int> b;
for (int i = 0; i < n - 1; i++) {
if (a[i] == 0) {
cout << -1 << '\n';
return 0;
}
sum += a[i];
b.push_back(sum);
}
map<int, int> mp;
for (int i = 0; i < n - 1; i++) {
/*if (b[i] > n || mp[b[i]]) {
cout << -1 << '\n';
return 0;
}*/
mp[b[i]] = 1;
}
int st = n - *max_element(b.begin(), b.end());
vector<int> ans;
ans.push_back(st);
for (int i = 0; i < n - 1; i++) {
ans.push_back(ans.back() + a[i]);
}
map<int, int> cnt;
for (int c : ans) {
cnt[c]++;
}
int new_cnt = 0;
for (int i = 1; i <= n; i++) {
new_cnt += cnt[i];
}
if (new_cnt != n || cnt[n] == 0) {
cout << -1 << '\n';
return 0;
}
for (int c : ans) {
cout << c << " ";
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Incorrect |
0 ms |
384 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Incorrect |
0 ms |
384 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Incorrect |
0 ms |
384 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
221 ms |
34024 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Incorrect |
198 ms |
32104 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Incorrect |
0 ms |
384 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |