/*
+----------------------------------------------------------------+
| In the name of Allah, the most Gracious and the most Merciful. |
+----------------------------------------------------------------+
Our hearts quake with fear of you
Our hearts wake with love for you
And to Islam we must be true
In everything we think and do.
--------------------------------
When your heart is breaking
And your pain makes you fall
Remember just remember
Allah Sees it all.
*/
# include <bits/stdc++.h>
# define FILE
using namespace std;
int main(){
# ifdef FILEs
freopen( "input.txt", "r", stdin );
freopen( "output.txt", "w", stdout );
# endif
ios_base::sync_with_stdio(false);
int n; cin >> n;
int d[n] = {};
for( int i = 1; i < n; i ++ ){
cin >> d[i];
}
long long cnt[n] = {}, eq = 0, mx = 0, mn = 0, id = -1, val = -1;
for( int i = 1; i < n; i ++ ){
cnt[i] = d[i] + cnt[i-1];
if( cnt[i] - mn == n-1 ){
id = i;
val = n;
eq = 1;
}
if( cnt[i] - mx == -n+1 ){
id = i;
val = 1;
eq = 1;
}
if( cnt[i] - mn > n-1 ){
cout << -1;
return 0;
}
if( cnt[i] - mx > -n+1 ){
cout << -1;
return 0;
}
mx = max( mx, cnt[i] );
mn = min( mn, cnt[i] );
}
if( !eq ) cout << -1;
else{
int a[n] = {};
a[id] = val;
for( int i = id+1; i < n; i ++ ){
a[i] = a[i-1] + d[i];
}
for( int i = id-1; i >= 0; i -- ){
a[i] = a[i+1] - d[i+1];
}
for( int i = 0; i < n; i ++ ){
cout << a[i] << ' ';
}cout << endl;
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Incorrect |
1 ms |
384 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Incorrect |
1 ms |
384 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Incorrect |
1 ms |
384 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
22 ms |
3832 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Incorrect |
1 ms |
384 KB |
Output isn't correct |