#include <bits/stdc++.h>
using namespace std;
int main() {
int N, M;
cin >> N >> M;
vector<int> a(N);
for (int i = 0; i < N; i++) cin >> a[i];
int best = 0; // số cột giữ lại nhiều nhất
// Duyệt tất cả tập con bằng bitmask
for (int mask = 1; mask < (1 << N); mask++) {
vector<int> sub;
for (int i = 0; i < N; i++) {
if (mask & (1 << i)) sub.push_back(a[i]); // giữ lại cột i
}
// Kiểm tra tập con này có hợp lệ không
bool ok = true;
int prevHeight = 0; // thỏ bắt đầu từ 0
for (int h : sub) {
if (h > prevHeight + M) { // không nhảy lên được
ok = false;
break;
}
prevHeight = h;
}
if (ok) best = max(best, (int)sub.size());
}
int ans = N - best; // số cột phải chỉnh sửa
cout << ans << "\n";
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |