# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
586137 | hibiki | Growing Vegetables is Fun 4 (JOI21_ho_t1) | C++11 | 1 ms | 312 KiB |
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 n, l, r, mx, po, ans;
int a[200005];
int main()
{
mx = 0, po = -1, ans = 0;
scanf("%d",&n);
for(int i = 0; i < n; i++)
{
scanf("%d",&a[i]);
if(a[i] > mx)
{
mx = a[i];
po = i;
}
}
l = max(po - 1, 0);
r = min(po + 1, n - 1);
if(l != po && a[l] == a[po])
ans++, a[po]++;
if(r != po && a[r] == a[po])
ans++, a[po]++;
while(l > 0 || r < n - 1)
{
int difl = 1e9, difr = 1e9;
if(l > 0)
difl = max(0, a[l - 1] - a[l] + 1);
if(r < n - 1)
difr = max(0, a[r + 1] - a[r] + 1);
if(difl < difr)
{
ans += difl;
a[r] += difl;
l--;
}
else
{
ans += difr;
a[l] += difr;
r++;
}
}
printf("%d\n",ans);
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |