# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1092704 | I_am_Polish_Girl | Growing Vegetables is Fun 4 (JOI21_ho_t1) | C++14 | 21 ms | 10244 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.
#pragma GCC optimize("Ofast")
#pragma GCC optimize("O3")
#pragma GCC optimization ("unroll-loops")
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#include <queue>
#include <cmath>
#include <random>
#include <chrono>
#include <iomanip>
#include <iostream>
#include <bitset>
#define int long long
using namespace std;
int log_ = 3;
int inf = 200000000000000;
int mod = 5;
int p = 505;
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int n;
cin >> n;
vector <int> a(n);
for (int i = 0; i < n; i++)
cin >> a[i];
vector <int> col(n);
vector <int> pref(n);
col[0] = 0;
pref[0] = a[0];
for (int i = 1; i < n; i++)
{
int x = 0;
if (a[i] <= a[i - 1])
{
x = a[i - 1] - a[i] +1;
}
col[i] = col[i - 1] + x;
pref[i] = a[i] + x;
}
vector <int> col_syf(n);
vector <int> pref_syf(n);
col_syf[n - 1] = 0;
pref_syf[n - 1] = a[n - 1];
for (int i = n - 2; i >= 0; i--)
{
int x = 0;
if (a[i] <= a[i + 1])
{
x = a[i + 1] - a[i] + 1;
}
col_syf[i] = col_syf[i + 1] + x;
pref_syf[i] = a[i] + x;
}
int ans = inf;
for (int i = 0; i < n; i++)
{
ans = min(ans, max(col[i], col_syf[i]));
}
cout << ans;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |