#include<bits/stdc++.h>
#define F first
#define S second
#define MAX 500005
#define oo 1e18
#define mod 1000000007
#define fast_in ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);cout.setf(ios::fixed);cout.precision(0);
using namespace std;
typedef long long ll;
#define pll pair<ll , ll>
#define vll vector<ll>
#define vvll vector<vll>
#define vpll vector<pll>
ll n,t[MAX],a[MAX],b[MAX];
int main(){
cin>>n;
for(int i=0;i<n;i++)cin>>a[i];
t[n-1]=0;
for(int i=n-2;i>=0;i--){
t[i]=t[i+1]+max((ll)0,(a[i+1]+1)-a[i]);
}ll s=0;ll ans=oo;
for(int i=0;i<n;i++){
if(i>0)s+=max((ll)0,(a[i-1]+1)-a[i]);
ans=min(ans,max(s,t[i]));
}cout<<ans<<"\n";
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4440 KB |
Output is correct |
2 |
Correct |
1 ms |
4540 KB |
Output is correct |
3 |
Correct |
1 ms |
4444 KB |
Output is correct |
4 |
Correct |
1 ms |
4444 KB |
Output is correct |
5 |
Correct |
1 ms |
4444 KB |
Output is correct |
6 |
Correct |
1 ms |
4444 KB |
Output is correct |
7 |
Correct |
1 ms |
4444 KB |
Output is correct |
8 |
Correct |
1 ms |
4444 KB |
Output is correct |
9 |
Correct |
1 ms |
4444 KB |
Output is correct |
10 |
Correct |
1 ms |
4444 KB |
Output is correct |
11 |
Correct |
1 ms |
4444 KB |
Output is correct |
12 |
Correct |
1 ms |
4444 KB |
Output is correct |
13 |
Correct |
1 ms |
4444 KB |
Output is correct |
14 |
Correct |
1 ms |
4444 KB |
Output is correct |
15 |
Correct |
1 ms |
4444 KB |
Output is correct |
16 |
Correct |
1 ms |
4560 KB |
Output is correct |
17 |
Correct |
1 ms |
4440 KB |
Output is correct |
18 |
Correct |
1 ms |
4444 KB |
Output is correct |
19 |
Correct |
1 ms |
4444 KB |
Output is correct |
20 |
Correct |
1 ms |
4444 KB |
Output is correct |
21 |
Correct |
1 ms |
4444 KB |
Output is correct |
22 |
Correct |
1 ms |
4444 KB |
Output is correct |
23 |
Correct |
1 ms |
4444 KB |
Output is correct |
24 |
Correct |
2 ms |
4700 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4440 KB |
Output is correct |
2 |
Correct |
1 ms |
4540 KB |
Output is correct |
3 |
Correct |
1 ms |
4444 KB |
Output is correct |
4 |
Correct |
1 ms |
4444 KB |
Output is correct |
5 |
Correct |
1 ms |
4444 KB |
Output is correct |
6 |
Correct |
1 ms |
4444 KB |
Output is correct |
7 |
Correct |
1 ms |
4444 KB |
Output is correct |
8 |
Correct |
1 ms |
4444 KB |
Output is correct |
9 |
Correct |
1 ms |
4444 KB |
Output is correct |
10 |
Correct |
1 ms |
4444 KB |
Output is correct |
11 |
Correct |
1 ms |
4444 KB |
Output is correct |
12 |
Correct |
1 ms |
4444 KB |
Output is correct |
13 |
Correct |
1 ms |
4444 KB |
Output is correct |
14 |
Correct |
1 ms |
4444 KB |
Output is correct |
15 |
Correct |
1 ms |
4444 KB |
Output is correct |
16 |
Correct |
1 ms |
4560 KB |
Output is correct |
17 |
Correct |
1 ms |
4440 KB |
Output is correct |
18 |
Correct |
1 ms |
4444 KB |
Output is correct |
19 |
Correct |
1 ms |
4444 KB |
Output is correct |
20 |
Correct |
1 ms |
4444 KB |
Output is correct |
21 |
Correct |
1 ms |
4444 KB |
Output is correct |
22 |
Correct |
1 ms |
4444 KB |
Output is correct |
23 |
Correct |
1 ms |
4444 KB |
Output is correct |
24 |
Correct |
2 ms |
4700 KB |
Output is correct |
25 |
Correct |
1 ms |
4440 KB |
Output is correct |
26 |
Correct |
55 ms |
10548 KB |
Output is correct |
27 |
Correct |
55 ms |
10320 KB |
Output is correct |
28 |
Correct |
55 ms |
10392 KB |
Output is correct |
29 |
Correct |
55 ms |
10576 KB |
Output is correct |
30 |
Correct |
41 ms |
9812 KB |
Output is correct |
31 |
Correct |
62 ms |
10388 KB |
Output is correct |
32 |
Correct |
55 ms |
10576 KB |
Output is correct |
33 |
Correct |
55 ms |
10576 KB |
Output is correct |
34 |
Correct |
55 ms |
10564 KB |
Output is correct |
35 |
Correct |
39 ms |
9768 KB |
Output is correct |
36 |
Correct |
41 ms |
9812 KB |
Output is correct |
37 |
Correct |
41 ms |
9636 KB |
Output is correct |
38 |
Correct |
54 ms |
10536 KB |
Output is correct |
39 |
Correct |
55 ms |
10580 KB |
Output is correct |
40 |
Correct |
56 ms |
10568 KB |
Output is correct |
41 |
Correct |
55 ms |
10320 KB |
Output is correct |
42 |
Correct |
51 ms |
10392 KB |
Output is correct |
43 |
Correct |
55 ms |
10540 KB |
Output is correct |
44 |
Correct |
55 ms |
10536 KB |
Output is correct |
45 |
Correct |
56 ms |
10324 KB |
Output is correct |
46 |
Correct |
55 ms |
10576 KB |
Output is correct |
47 |
Correct |
56 ms |
10580 KB |
Output is correct |
48 |
Correct |
55 ms |
10412 KB |
Output is correct |