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 <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <tuple>
#include <math.h>
#include <set>
#include <stack>
#include <bitset>
#include <map>
#include <queue>
#include <random>
#include <array>
#include <unordered_set>
#include <cassert>
#include <unordered_map>
#define DEBUG
#define pqueue priority_queue
#define pb(x) push_back(x)
//#define endl '\n'
#define all(x) x.begin(), x.end()
#define int long long
#define mk(a, b) make_pair(a, b)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef vector<ull> vull;
typedef vector<ll> vll;
// typedef tuple<ll, ll, ll> tiii;
typedef pair<int, int> pii;
typedef vector<pair<int, int> > vpii;
typedef pair<ll, ll> pll;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef vector<vector<int> > vvi;
typedef vector<char> vc;
const ll inf = 1e9 + 228;
const ll infll = 1e18;
const ll mod = 1e9 + 7;
//static const int maxn = 1e6 + 228;
const ld eps = 3e-9;
const ll mod2 = 998244353;
const ld PI = atan2l(0, -1);
void fast_io() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
// freopen("2", "r", stdin);
// freopen("output.txt", "w", stdout);
}
void solve() {
int n;
cin >> n;
vi a(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
}
vi pref1(n);
for (int i = 1; i < n; i++) {
pref1[i] = pref1[i - 1];
if (a[i] <= a[i - 1])
pref1[i] += a[i - 1] - a[i] + 1;
}
vi pref2(n);
for (int i = n - 2; i >= 0; i--) {
pref2[i] = pref2[i + 1];
if (a[i] <= a[i + 1])
pref2[i] += a[i + 1] - a[i] + 1;
}
int ans = infll;
for(int j=0; j<n; j++){
int cur = max(pref1[j], pref2[j]);
ans = min(ans, cur);
}
cout << ans << endl;
}
signed main() {
fast_io();
srand(time(NULL));
int q = 1;
// cin >> q;
while (q--)
solve();
} //
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |