#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
void speed()
{
ios_base::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
}
int main()
{
speed();
int n; cin>>n;
ll a[n];
for(int i=0; i<n; i++)cin>>a[i];
ll razlike[n]; razlike[0]=0; //razlike[i]=a[i]-a[i-1]
for(int i=1; i<n; i++)razlike[i]=a[i]-a[i-1];
ll preff[n], suff[n];
preff[0]=0; suff[n-1]=0;
for(int i=1; i<n; i++)
{
if(razlike[i]<=0)preff[i]=-razlike[i]+1;
preff[i]+=preff[i-1];
}
for(int i=n-2; i>=0; i--)
{
if(razlike[i]>=0)suff[i]=razlike[i]+1;
suff[i]+=suff[i+1];
}
ll rezz=INT_MAX;
for(int i=0; i<n; i++)
{
rezz=min(rezz, max(suff[i], preff[i]));
}
cout<<rezz;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |