이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
int main()
{
ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
int n;
cin >> n;
int a[n] = {};
int pref = 0, mx_pref = INT_MIN;
for(int i = 0; i < n - 1; ++i) {
cin >> a[i];
pref += a[i];
mx_pref = max(mx_pref, pref);
}
if(mx_pref != n - 1) {
cout << -1;
}
else {
int first = n;
pref = 0;
for(int i = 0; i < n - 1; ++i) {
pref += a[i];
first = min(first, max(1, 1 - pref));
}
pref = 0;
vector<int> ans(n);
bool ok = true;
for(int i = 0; i < n; ++i) {
ans.push_back(first + pref);
pref += a[i];
if(first + pref < 1 or first + pref > n)
ok = false;
}
if(ok){
for(int i = 0; i < n; ++i)
cout << ans[i] << " ";
}
else {
cout << -1;
}
}
}
| # | 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... |