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