Submission #1247640

#TimeUsernameProblemLanguageResultExecution timeMemory
1247640wedonttalkanymoreGrowing Vegetables is Fun 4 (JOI21_ho_t1)C++20
100 / 100
13 ms4988 KiB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

#define int long long
#define pii pair<ll, ll>
#define fi first
#define se second

const ll N = 2e5 + 5, inf = 1e18, mod = 1e9 + 7, block = 320, lim = 1 << 16;

int n, a[N];
int diff[N], diff1[N];
int pos[N], pos1[N];

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    if (fopen(".inp", "r")) {
        freopen(".inp", "r", stdin);
        freopen(".out", "w", stdout);
    }
	cin >> n;
	for (int i = 1; i <= n; i++) cin >> a[i];
	for (int i = 1; i <= n; i++) {
		diff[i] = diff[i - 1] + max(0LL, a[i - 1] - a[i] + 1);
	}
	for (int i = n; i >= 1; i--) {
		diff1[i] = diff1[i + 1] + max(0LL, a[i + 1] - a[i] + 1);
	}
	int ans = inf;
	for (int i = 1; i <= n; i++) {
		ans = min(ans, max(diff[i], diff1[i]));
	}
	cout << ans;
    return 0;
}

Compilation message (stderr)

Main.cpp: In function 'int main()':
Main.cpp:20:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   20 |         freopen(".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~
Main.cpp:21:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   21 |         freopen(".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...