이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
/*
* 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
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |