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<int> A(N);
for (int i = 0; i < N; i++)
{
cin >> A[i];
}
long long tot = 0;
int a = 1, b = N - 2, adda = 0, addb = 0;
while (a < b)
{
while (A[a - 1] - adda < A[a])
{
a++;
adda = 0;
}
while (A[b + 1] - addb < A[b])
{
b--;
addb = 0;
}
if (a >= b)
break;
int m = min(A[a - 1] - A[a] + 1 - adda, A[b + 1] - A[b] + 1 - addb);
adda += m;
addb += m;
tot += m;
}
if (A[a] == A[b] && a == b + 1)
tot++;
cout << tot;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |