제출 #657904

#제출 시각아이디문제언어결과실행 시간메모리
657904kussssoStove (JOI18_stove)C++14
50 / 100
438 ms262144 KiB
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 1e5 + 5;
const ll inf = 1e18;

int n, k;
ll t[N], dp[5005][5005];

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    
    cin >> n >> k;
    for (int i = 1; i <= n; i++) cin >> t[i];
    for (int i = 0; i <= n; i++) for (int j = 0; j <= n; j++) dp[i][j] = inf;
    dp[0][0] = 0;
    for (int z = 1; z <= k; z++) {
        ll min_dp = inf;
        for (int i = 1; i <= n; i++) {
            min_dp = min(min_dp, dp[i - 1][z - 1] - t[i]);
            dp[i][z] = min(dp[i][z], min_dp + t[i] + 1);
        }
    }
    cout << dp[n][k];
    
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...