Submission #831984

#TimeUsernameProblemLanguageResultExecution timeMemory
831984konberStove (JOI18_stove)C++14
50 / 100
155 ms198348 KiB
#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", &times[i]);

    memset(memo, -1, sizeof memo);
    cout << dp(0, K) << endl;
}

Compilation message (stderr)

stove.cpp: In function 'int main()':
stove.cpp:28:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   28 |     scanf("%d%d", &N, &K);
      |     ~~~~~^~~~~~~~~~~~~~~~
stove.cpp:31:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   31 |         scanf("%lld", &times[i]);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...