Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- typedef long long ll;
- const ll maxn = 1e5 + 10;
- const ll inf = 2e18;
- ll n, a[maxn], mx = -1, ind, ans = 0, was[maxn], k[maxn];
- int main() {
- ios_base::sync_with_stdio(0);
- cin >> n;
- for (int i = 0; i < n; ++i) {
- cin >> a[i];
- }
- for (int i = 0; i < n; ++i) {
- if (mx < a[i]) {
- ll need = a[i] - mx;
- mx = a[i];
- for (ll j = i; j >= 0; --j) {
- if (was[j] == 0) {
- was[j] = 1;
- need--;
- }
- if (need == 0) {
- break;
- }
- }
- }
- }
- ll now = 0;
- for (ll i = 0; i < n; ++i) {
- if (was[i]) now++;
- ans += now - a[i] - 1;
- }
- cout << ans;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement