| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 281816 | BeanZ | Stove (JOI18_stove) | C++14 | 102 ms | 153080 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;
#define ll long long
#define endl '\n'
const int N = 1e5 + 5;
const int mod = 1e9 + 7;
ll a[5005], dp[5005][5005][2];
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
if (fopen("VietCT.INP", "r")){
freopen("VietCT.INP", "r", stdin);
freopen("VietCT.OUT", "w", stdout);
}
ll n, k;
cin >> n >> k;
for (int i = 1; i <= n; i++) cin >> a[i];
for (int i = 0; i <= n; i++){
for (int j = 0; j <= k; j++){
for (int x = 0; x < 2; x++){
dp[i][j][x] = 1e10;
}
}
}
dp[1][1][0] = 1;
dp[1][1][1] = 1;
for (int i = 2; i <= n; i++){
for (int j = 1; j <= min(1ll * i, k); j++){
dp[i][j][0] = min(dp[i][j][0], dp[i - 1][j][0] + a[i] - a[i - 1]);
dp[i][j][0] = min(dp[i][j][0], dp[i - 1][j - 1][1] + 1);
dp[i][j][1] = min(dp[i][j][1], dp[i - 1][j][0] + a[i] - a[i - 1]);
dp[i][j][1] = min(dp[i][j][1], dp[i - 1][j - 1][1] + 1);
}
}
ll ans = 1e18;
for (int i = 1; i <= k; i++){
ans = min(ans, dp[n][i][1]);
}
cout << ans;
}
/*
*/
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... | ||||
