#include<bits/stdc++.h>
#define mod 1000000007
#define inf 0x3f3f3f3f
#define bit(x,i)(((x)>>(i))&1)
#define FAST ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
using namespace std;
ifstream fin("partit.in");
ofstream fout("partit.out");
const long long int mare=1LL*1000000000000000000;
long long int T,n,m,ok,i,j,k,t;
long long int c,aux,start,maxx,summax,minn;
long long int contor,suma,poz,dim;
long long int v[200005],st[200005],dr[200005],sumst[200005],sumdr[200005];
int main()
{
cin>>n;
for(i=1;i<=n;i++)
{
cin>>v[i];
}
st[1]=v[1];
for(i=2;i<=n;i++)
{
st[i]=v[i]+sumst[i-1];
sumst[i]=sumst[i-1];
if(st[i]<=st[i-1])
{
sumst[i]+=(st[i-1]-st[i])+1;
st[i]=st[i-1]+1;
}
}
dr[n]=v[n];
for(i=n-1;i>=1;i--)
{
dr[i]=v[i]+sumdr[i+1];
sumdr[i]=sumdr[i+1];
if(dr[i]<=dr[i+1])
{
sumdr[i]+=(dr[i+1]-dr[i])+1;
dr[i]=dr[i+1]+1;
}
}
contor=mare;
for(i=1;i<=n;i++)
{
contor=min(contor,max(sumst[i],sumdr[i]));
}
cout<<contor;
return 0;
}
/*
7
12 2 34 85 4 91 3
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
316 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
328 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
2 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
320 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
468 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
332 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
316 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
328 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
2 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
320 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
468 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
332 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
352 KB |
Output is correct |
26 |
Correct |
59 ms |
9940 KB |
Output is correct |
27 |
Correct |
86 ms |
9932 KB |
Output is correct |
28 |
Correct |
59 ms |
10044 KB |
Output is correct |
29 |
Correct |
58 ms |
10040 KB |
Output is correct |
30 |
Correct |
45 ms |
9388 KB |
Output is correct |
31 |
Correct |
58 ms |
10056 KB |
Output is correct |
32 |
Correct |
58 ms |
9960 KB |
Output is correct |
33 |
Correct |
72 ms |
10028 KB |
Output is correct |
34 |
Correct |
58 ms |
9984 KB |
Output is correct |
35 |
Correct |
42 ms |
9164 KB |
Output is correct |
36 |
Correct |
45 ms |
9360 KB |
Output is correct |
37 |
Correct |
46 ms |
9376 KB |
Output is correct |
38 |
Correct |
58 ms |
10000 KB |
Output is correct |
39 |
Correct |
58 ms |
9964 KB |
Output is correct |
40 |
Correct |
70 ms |
10072 KB |
Output is correct |
41 |
Correct |
60 ms |
10044 KB |
Output is correct |
42 |
Correct |
55 ms |
9768 KB |
Output is correct |
43 |
Correct |
58 ms |
9968 KB |
Output is correct |
44 |
Correct |
57 ms |
9944 KB |
Output is correct |
45 |
Correct |
58 ms |
10000 KB |
Output is correct |
46 |
Correct |
65 ms |
10132 KB |
Output is correct |
47 |
Correct |
60 ms |
10032 KB |
Output is correct |
48 |
Correct |
60 ms |
10064 KB |
Output is correct |