# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
136940 | ksmzzang2003 | 오렌지 출하 (JOI16_ho_t1) | C++14 | 78 ms | 1656 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 ll;
ll N,M,K,arr[20003],memo[20003];
ll f(ll n) {
if(n<0)
return 1LL<<61;
if(n==0)
return 0;
if(memo[n]!=-1)
return memo[n];
ll ret = 1LL<<60;
ll maxv=-1,minv=1LL<<61;
for(ll i=n; i>=n-M+1; i--) {
maxv = max(maxv,arr[i]); minv= min(minv,arr[i]);
ret = min(ret,f(i-1)+K+(n+1-i)*(maxv-minv));
}
return memo[n] = ret;
}
int main() {
fill(memo,memo+20003,-1);
scanf("%lld %lld %lld",&N,&M,&K);
for(ll i=1; i<=N; i++)
scanf("%lld",&arr[i]);
printf("%lld",f(N));
}
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... |