/*
* author: robosapien
* created: 2020-11-09 23:46:27
*/
#include<bits/stdc++.h>
using namespace std;
#define bs ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define ll long long int
#define pb push_back
#define all(x) x.begin(),x.end()
#define ff first
#define ss second
#define pii pair<int,int>
void solve(){
int n;
cin >> n;
int a[n] = {};
for(int i = 0; i < n - 1; ++i) cin >> a[i];
int pos_pref = 0, neg_pref = 0, mx_pref = INT_MIN, mn_pref = INT_MAX;
for(int i = 0; i < n - 1; ++i) {
if(a[i] > 0)
pos_pref += a[i], neg_pref = 0;
if(a[i] < 0)
neg_pref += a[i], pos_pref = 0;
mx_pref = max(pos_pref, mx_pref);
mn_pref = min(neg_pref, mn_pref);
}
if(mn_pref == -n + 1 || mx_pref == n - 1) {
int fi = 1;
int pref = 0;
for(int i = 0; i < n - 1; ++i) {
pref += a[i];
fi = max(fi, 1 - pref);
}
vector<int> ans(n);
pref = 0;
if(fi < 1) {
cout << -1;
return;
}
for(int i = 0; i < n; ++i) {
if(fi + pref < 1 or fi + pref > n) {
cout << -1;
return;
}
ans[i] = (fi + pref);
pref += a[i];
}
for(int i = 0; i < n; ++i)
cout << ans[i] << " ";
} else {
cout << -1;
}
}
int main()
{
bs;
int t = 1;
// cin >> t;
while(t--){
solve();
}
#ifdef LOCAL_DEFINE
cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
0 ms |
364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
0 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
0 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
0 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
0 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
48 ms |
5092 KB |
Output is correct |
2 |
Correct |
1 ms |
512 KB |
Output is correct |
3 |
Correct |
51 ms |
5092 KB |
Output is correct |
4 |
Correct |
20 ms |
1772 KB |
Output is correct |
5 |
Correct |
24 ms |
1772 KB |
Output is correct |
6 |
Correct |
24 ms |
1772 KB |
Output is correct |
7 |
Correct |
22 ms |
1772 KB |
Output is correct |
8 |
Correct |
25 ms |
1772 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
0 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
0 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |