Submission #708013

#TimeUsernameProblemLanguageResultExecution timeMemory
708013rainboyGrowing Vegetables is Fun 4 (JOI21_ho_t1)C11
100 / 100
30 ms3000 KiB
#include <stdio.h>

#define N	200000

long long min(long long a, long long b) { return a < b ? a : b; }
long long max(long long a, long long b) { return a > b ? a : b; }

int main() {
	static int aa[N];
	int n, i;
	long long x, y, ans;

	scanf("%d", &n);
	for (i = 0; i < n; i++)
		scanf("%d", &aa[i]);
	x = 0, y = 0;
	for (i = 1; i < n; i++)
		y += max(aa[i] - aa[i - 1] + 1, 0);
	ans = y;
	for (i = 1; i < n; i++) {
		x += max(aa[i - 1] - aa[i] + 1, 0), y -= max(aa[i] - aa[i - 1] + 1, 0);
		ans = min(ans, max(x, y));
	}
	printf("%lld\n", ans);
	return 0;
}

Compilation message (stderr)

Main.c: In function 'main':
Main.c:13:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   13 |  scanf("%d", &n);
      |  ^~~~~~~~~~~~~~~
Main.c:15:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   15 |   scanf("%d", &aa[i]);
      |   ^~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...