# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
831984 | konber | Stove (JOI18_stove) | C++14 | 155 ms | 198348 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 <iostream>
#include <vector>
#include <cstring>
using namespace std;
typedef long long ll;
vector<ll> times;
ll memo[5005][5005];
int N;
ll dp(int i, int remK){
if(remK < 0) return 1e15;
if(i==N) return 0;
if(memo[i][remK] != -1) return memo[i][remK];
ll ch1=1e15;
if(i){
ch1 = dp(i+1, remK) + times[i]+1 - times[i-1]-1;
}
ll ch2 = dp(i+1, remK-1) + 1;
return memo[i][remK] = min(ch1, ch2);
}
int main()
{
int K;
scanf("%d%d", &N, &K);
times.resize(N);
for(int i=0; i < N; i++)
scanf("%lld", ×[i]);
memset(memo, -1, sizeof memo);
cout << dp(0, K) << endl;
}
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... |