#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 = times[n-1];
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) ans = min(ans, total_on);
}
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... |