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>
#include <string.h>
#define N 20000
#define INF 0x3f3f3f3f3f3f3f3fLL
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];
static long long dp[N + 1];
int n, m, c, i, j;
long long mn, mx;
scanf("%d%d%d", &n, &m, &c);
for (i = 0; i < n; i++)
scanf("%d", &aa[i]);
memset(dp, 0x3f, (n + 1) * sizeof *dp), dp[0] = 0;
for (i = 0; i < n; i++) {
mn = INF, mx = 0;
for (j = i + 1; j <= n && j - i <= m; j++) {
mn = min(mn, aa[j - 1]), mx = max(mx, aa[j - 1]);
dp[j] = min(dp[j], dp[i] + (mx - mn) * (j - i) + c);
}
}
printf("%lld\n", dp[n]);
return 0;
}
Compilation message (stderr)
2016_ho_t1.c: In function 'main':
2016_ho_t1.c:16:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
16 | scanf("%d%d%d", &n, &m, &c);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~
2016_ho_t1.c:18:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
18 | scanf("%d", &aa[i]);
| ^~~~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |