Submission #1134736

#TimeUsernameProblemLanguageResultExecution timeMemory
1134736lopkusRabbit Carrot (LMIO19_triusis)C++20
0 / 100
94 ms4464 KiB
#include <bits/stdc++.h>

#define int long long

using namespace std;

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, k;
    cin >> n >> k;
    vector<int> a(n + 1);
    for(int i = 1; i <= n; i++) {
        cin >> a[i];
    }
    int dp[n + 1][102];
    for(int i = 0; i <= n; i++) {
        for(int j = 0; j <= 101; j++) {
            dp[i][j] = n + 1;
        }
    }
    for(int j = 1; j <= 101; j++) {
        dp[1][j] = (a[1] != j);
    }
    for(int i = 2; i <= n; i++) {
        for(int j = 1; j <= 101; j++) {
            for(int q = 1; q <= 101; q++) {
                if(j - q <= k) {
                    dp[i][j] = min(dp[i][j], dp[i - 1][q] + (a[i] != j));
                }
            }
        }
    }
    int ans = n + 1;
    for(int i = 1; i <= 101; i++) {
        ans = min(ans, dp[n][i]);
    }
    cout << ans;
}

#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...