#include <bits/stdc++.h>
using namespace std;
const int MX=2e5+5;
int N;
int A[MX], B[MX], C[MX], pf[MX], sf[MX];
int main() {
cin.tie(0); ios_base::sync_with_stdio(0);
cin>>N;
for(int i=1;i<=N;i++) {
cin>>A[i];
B[i]=A[i]-A[i-1];
}
B[N+1]=A[N+1]-A[N];
for(int i=1;i<=N+1;i++) {
pf[i]+=pf[i-1];
if(B[i]<=0)
pf[i]+=1-B[i];
}
for(int i=N;i>=1;i--) {
sf[i]+=sf[i+1];
if(B[i+1]>=0)
sf[i]+=B[i+1]+1;
}
int ans=pf[N];
for(int i=1;i<=N;i++) {
ans=min(ans,max(pf[i],sf[i]));
}
cout<<ans<<'\n';
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |