제출 #1144729

#제출 시각아이디문제언어결과실행 시간메모리
1144729why1Stove (JOI18_stove)C++20
50 / 100
157 ms327680 KiB
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define pb push_back
#define pii pair<int,int>
#define sz size()
#define all(v) v.begin(),v.end()
#define fi first
#define se second

const int N = 2e5;
const int mod = 1e9+7;
const ll INF = 1e18;

const int di[] = {1, -1, 0, 0};
const int dj[] = {0, 0, 1, -1};

void solve() {
	int n,k;
	cin>>n>>k;
	ll a[n+1];
	for(int i = 1; i <= n; i++){
		cin>>a[i];
	}
	ll dp[n+1][k+1],pref[n+1][k+1];
	for(int i = 0; i <= n; i++){
		for(int j = 0; j <= k; j++){
			dp[i][j]=INF;
			pref[i][j]=INF;
		}
	}
	dp[0][0]=0;
	for(int i = 1; i <= n; i++){
		for(int K = 0; K < min(i,k); K++){
			pref[i][K]=min(pref[i-1][K],dp[i-1][K]-a[i]+1);
		}
		for(int K = 1; K <= min(i,k); K++){
			dp[i][K]=pref[i][K-1]+a[i];
		}
	}
	ll ans=INF;
	for(int i = 1; i <= k; i++){
		ans=min(ans,dp[n][i]);
	}
	cout<<ans<<"\n";
}

int main() {

	//freopen("cowrun.in","r",stdin);
	//freopen("cowrun.out","w",stdout);

    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

	int t=1;
	//cin>>t;
	while(t--) {
        solve();
	}

    return 0;
}

#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...