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;
int main()
{
int n;
cin >> n;
vector<long long> v(n);
for (int i=0;i<n;i++)
cin >> v[i];
int l=1,r=n-2,brojac=0;
while (l<n)
if (v[l-1]<v[l]) l++;
else break;
while (r>=0)
if (v[r+1]<v[r]) r--;
else break;
//cout << l << " " << r << endl;
if (l==n||r==-1)
{
cout << 0 << endl;
return 0;
}
while (l<r)
{
if (v[l-1]<v[l])
{
l++;
continue;
}
if (v[r+1]<v[r])
{
r--;
continue;
}
int najm=min(v[l-1]-v[l]+1,v[r+1]-v[r]+1);
for (int i=l;i<=r;i++)
v[i]+=najm;
brojac+=najm;
}
if (v[l]<=v[l-1])
brojac+=v[l-1]-v[l]+1;
cout << brojac;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |