This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define int long long
#define pb push_back
#define fi first
#define se second
#define X first
#define Y second
#define ist insert
typedef long long ll;
//typedef pair<int,int> pii;
using namespace std;
int max(int a,int b){return a>b?a:b;}
int min(int a,int b){return a<b?a:b;}
const int INF=17000000000000000;//2147483647;
const int MOD=998244353;//1000000007;
const int N=200005;
int n;
int a[N],b[N];
int L[N],R[N];
void calc(){
int s1=0,s2=0;
for (int i=1;i<=n;i++){
if (b[i]<=0)
s1+=-b[i]+1;
L[i]=s1;
}
for (int i=n;i>=1;i--){
if (b[i]>=0)
s2+=b[i]+1;
R[i]=s2;
}
}
void sol(){
cin >>n;
for (int i=1;i<=n;i++)
cin >>a[i];
for (int i=1;i<=n;i++)
b[i]=a[i]-a[i-1];
calc();
int ans=INF;
for (int i=1;i<=n;i++)
ans=min(ans,max(L[i],R[i+1]));
cout <<ans<<'\n';
}
signed main()
{
int _=1;
//cin >>_;
while (_--) sol();
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |