Submission #909631

#TimeUsernameProblemLanguageResultExecution timeMemory
909631MilosMilutinovic오렌지 출하 (JOI16_ho_t1)C++14
100 / 100
40 ms1284 KiB
#include<bits/stdc++.h>
 
#define pb push_back
#define fi first
#define se second
#define mp make_pair
 
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef long double ld;
 
template <typename T> bool chkmin(T &x,T y){return x>y?x=y,1:0;}
template <typename T> bool chkmax(T &x,T y){return x<y?x=y,1:0;}

int readint(){
	int x=0,f=1; char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}

int n,m,k,a[20005];
ll dp[20005];
 
int main(){
	n=readint(); m=readint(); k=readint();
	for(int i=1;i<=n;i++) a[i]=readint();
	for(int i=1;i<=n;i++){
		dp[i]=1e18;
		int mn=a[i],mx=a[i];
		for(int j=i;j>max(0,i-m);j--){
			mn=min(mn,a[j]);
			mx=max(mx,a[j]);
			dp[i]=min(dp[i],dp[j-1]+k+(i-j+1)*1ll*(mx-mn));
		}
	}
	printf("%lld\n",dp[n]);
	return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...