This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
/******************************************************************************
Online C++ Compiler.
Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.
*******************************************************************************/
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin>>n;
int d[n-1];
for(int i = 0;i<n-1;i++)cin>>d[i];
int a[n];
a[0]=0;
int idx = 0;
for(int i = 0;i<n-1;i++){
a[i+1]=a[i]+d[i];
if(a[i+1]>a[idx])idx=i+1;
}
a[idx]=n;
int mn = n;
for(int i = idx+1;i<n;i++){
a[i]=a[i-1]+d[i-1];
mn=min(mn,a[i]);
}
for(int i = idx-1;i>=0;i--){
a[i]=a[i+1]-d[i];
mn=min(mn,a[i]);
}
if(mn!=1){
cout<<-1;
return 0;
}
for(int i = 0;i<n;i++)cout<<a[i]<<" ";
}
# | 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... |