Submission #1131856

#TimeUsernameProblemLanguageResultExecution timeMemory
1131856lopkus오렌지 출하 (JOI16_ho_t1)C++20
100 / 100
44 ms764 KiB
#include <bits/stdc++.h>

#define int long long

using namespace std;

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n, m, k;
    cin >> n >> m >> k;
    vector<int> a(n + 1);
    for(int i = 1; i <= n; i++) {
        cin >> a[i];
    }
    vector<int> dp(n + 1, 1e18);
    dp[0] = 0;
    for(int i = 1; i <= n; i++) {
        int mx = 0;
        int mn = 1e18;
        for(int j = i; j >= 1; j--) {
            if(i - j + 1 > m) {
                break;
            }
            mx = max(mx, a[j]);
            mn = min(mn, a[j]);
            dp[i] = min(dp[i], dp[j - 1] + (i - j + 1) * (mx - mn) + k);
        }
    }
    cout << dp[n];
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...