# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
58738 | leejseo | 오렌지 출하 (JOI16_ho_t1) | C++98 | 49 ms | 46464 KiB |
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 <bits/stdc++.h>
using namespace std;
typedef long long lld;
const lld UNDEF = 1LL << 60;
const int MAXN = 2000;
int N, M;
lld K, A[MAXN+1], B[MAXN+1][MAXN+1], C[MAXN+1][MAXN+1], D[MAXN+1];
void input(){
scanf("%d%d%lld", &N, &M, &K);
for (int i=0; i<N; i++) scanf("%lld", &A[i+1]);
}
void init(){
for (int i=1; i<=N; i++){
C[i][i] = A[i];
B[i][i] = A[i];
for (int j=i+1; j<=N; j++) B[i][j] = max(B[i][j-1], A[j]);
for (int j=i+1; j<=N; j++) C[i][j] = min(C[i][j-1], A[j]);
}
}
void DP(){
D[0] = 0;
for (int i=1; i<=N; i++){
D[i] = D[i-1]+K;
for (int k=max(1, i-M+1); k<i; k++){
D[i] = min(D[i], D[k-1] + K + (i-k+1) * (B[k][i] - C[k][i]));
}
}
printf("%lld\n", D[N]);
}
int main(){
input();
init();
DP();
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |