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 endl "\n"
#define finp for(int i=0; i<n; i++)
#define fknp for(int k=0; k<n; k++)
#define yeap cout<<"YES"<<endl
#define nope cout<<"NO"<<endl
#define inpintn int n; cin>>n
#define inpintarrn int arr[n]; for(int i=0; i<n; i++){cin>>arr[i];}
#define inpllarrn long long arr[n]; for(int i=0; i<n; i++){cin>>arr[i];}
#define ll long long
using namespace std;
int main ()
{
int n;
cin>>n;
int ar[n];
int z=n-1;
int arr[z];
int l1=0;
int l=0;
int r=0;
for (int i=0; i<n; i++){
if(i==0){
cin>>ar[i];
} else {
cin>>ar[i];
arr[i-1]=ar[i-1]-ar[i];
}
}
for (int i=0; i<z; i++){
if(arr[i]<0){
r=r-arr[i]+1;
} else if(arr[i]>0){
l1=l1+arr[i]+1;
} else if (arr[i]==0){
l1++;
r++;
}
}
int ans=r;
int maxx;
for (int i=1; i<z; i++){
if(arr[i-1]>0){
l=l+arr[i-1]+1;
} else if(arr[i-1]<0){
r=r+arr[i-1]-1;
} else if(arr[i-1]==0){
l++;
r--;
}
if (l<r){
maxx=r;
} else {
maxx=l;
}
if (maxx<ans){
ans=maxx;
} else {
ans=ans;
}
}
if(l1<ans){
cout<<l1<<endl;
} else {
cout<<ans<<endl;
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |