# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
377667 | Lawliet | Growing Vegetables is Fun 4 (JOI21_ho_t1) | C++17 | 36 ms | 2028 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;
typedef long long int lli;
typedef pair<int,int> pii;
const int MAXN = 200010;
const int INF = 1000000010;
const lli INFLL = 1000000000000000010;
int v[MAXN];
int diff[MAXN];
void solveTestCase(int testCase)
{
int n;
scanf("%d",&n);
for(int i = 1 ; i <= n ; i++)
scanf("%d",&v[i]);
for(int i = 1 ; i < n ; i++)
diff[i] = v[i + 1] - v[i];
lli ans = INFLL;
lli ansLeft = 0;
lli ansRight = 0;
for(int i = 1 ; i < n ; i++)
if( diff[i] >= 0 ) ansRight += diff[i] + 1;
for(int i = 1 ; i <= n ; i++)
{
lli curAns = max( ansLeft , ansRight );
ans = min( ans , curAns );
if( diff[i] >= 0 )
ansRight -= diff[i] + 1;
if( diff[i] <= 0 )
ansLeft += -diff[i] + 1;
}
printf("%lld\n",ans);
}
int main()
{
int qtdTestCases = 1;
// scanf("%d",&qtdTestCases);
for(int testCase = 1 ; testCase <= qtdTestCases ; testCase++)
solveTestCase( testCase );
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |