# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1261582 | blueviolet | Stove (JOI18_stove) | C++20 | 231 ms | 196580 KiB |
#include <bits/stdc++.h>
#define ll long long
#define io(x) if (fopen(x".inp","r")) {freopen(x".inp","r",stdin),freopen(x".out","w",stdout);}
#define TimeRun {End=clock();cerr<<"Time run: "<<(float)(End-Begin)/CLOCKS_PER_SEC<<"s"<<el;}
#define mem(c, x) memset(c, x, sizeof(c))
#define all(c) c.begin(), c.end()
#define bit(i,j) ((i >> j) & 1)
#define se second
#define fi first
#define el '\n'
using namespace std;
template<class X, class Y> bool maximize(X &a, const Y &b) { return (a < b ? a = b, 1 : 0); }
template<class X, class Y> bool minimize(X &a, const Y &b) { return (a > b ? a = b, 1 : 0); }
int dx[8] = {0, 1, 0,-1, 1, 1,-1,-1};
int dy[8] = {1, 0,-1, 0, 1,-1,-1, 1};
const int maxn = 5e3 + 2;
const int Inf = 2e9 + 7;
const ll Infll = 1e18 + 9;
const ll Mod = 1e9 + 7;
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
int n, k, a[maxn];
ll dp[maxn][maxn];
void solve() {
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++) dp[i][j] = Infll;
}
dp[0][0] = 0;
for (int i=1; i<=n; i++) {
for (int j=1; j<=min(k, i); j++) {
dp[i][j] = min(dp[i-1][j-1] + 1, dp[i-1][j] + a[i]-a[i-1]);
}
}
cout << dp[n][k];
}
signed main() {
ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); clock_t Begin = clock(), End;
io("task");
solve();
TimeRun; return (0 ^ 0);
}
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... |