Submission #1269554

#TimeUsernameProblemLanguageResultExecution timeMemory
1269554lucasmin2011Rabbit Carrot (LMIO19_triusis)C++20
0 / 100
33 ms328 KiB
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int N, M; cin >> N >> M; vector<long long> a(N + 1); a[0] = 0; // starting height for (int i = 1; i <= N; i++) cin >> a[i]; vector<int> dp(N + 1, 1e9); dp[0] = 0; for (int i = 1; i <= N; i++) { for (int j = 0; j < i; j++) { // If jump from pole j to i is possible if (a[i] <= a[j] + M) { dp[i] = min(dp[i], dp[j] + (i - j - 1)); // (i-j-1) = poles between j and i must be modified } } // Always possible to just modify pole i itself dp[i] = min(dp[i], dp[i-1] + 1); } cout << dp[N] << "\n"; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...