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 <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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |