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>
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 pozitivni[n], negativni[n];
pozitivni[0]=0; negativni[0]=0;
for(int i=1; i<n; i++)
{
pozitivni[i]=pozitivni[i-1];
negativni[i]=negativni[i-1];
if(razlike[i]>=0)negativni[i]+=razlike[i]+1;
if(razlike[i]<=0)pozitivni[i]-=razlike[i]+1;
}
ll rezz=INT_MAX;
for(int i=0; i<n; i++)
{
rezz=min(rezz, max(negativni[n-1]-negativni[i], pozitivni[i]));
}
cout<<rezz;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |