#include <bits/stdc++.h>
using namespace std;
int main() {
cin.tie(0)->sync_with_stdio(0);
int n, k; cin >> n >> k;
vector<int> times(n);
for (int i = 0; i < n; i++) {
cin >> times[i];
times[i]--;
}
int ans = 21;
// int best = 0;
for (int mask = 0; mask < (1 << 20); mask++) {
int matches = 0, total_on = 0;
for (int i = 0; i < 20; i++) {
if (!(mask & (1 << i))) continue;
total_on++;
if (i == 0) matches++;
if (i > 0 && !(mask & (1 << (i-1)))) matches++;
}
if (matches > k) continue;
bool can = true; for (int i = 0; i < n; i++) can = can && (mask & (1 << times[i]));
if (can && total_on < ans) {
ans = total_on;
// best = mask;
}
}
// for (int i = 0; i < 20; i++) cerr << (best & (1 << i)) ? 1 : 0;
// cerr << "\n";
cout << ans << "\n";
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |