#include <bits/stdc++.h>
// #pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
// #pragma GCC optimize("Ofast")
// #pragma GCC target("avx,avx2,fma")
// #pragma GCC optimization("unroll-loops")
// #pragma ("reroll")
#define all(v) v.begin(), v.end()
#define skip continue;
#define gold ios_base::sync_with_stdio(false);cin.tie(NULL);
#define xa "\n"
#define int long long
#define pb push_back
#define S second
#define F first
using namespace std;
const int mod = 1e9 + 7;
const int N = 1e6 + 7;
const int MAX = 1e9;
const int inf = 1e18;
int gcd(int a, int b) { if (b == 0) return a; else if(a == 0) return b; else return gcd(b, a % b); }
int lcm(int a, int b) { return a / gcd(a, b) * b; }
void solve() {
int n, k;
cin >> n >> k;
int a[n + 1];
map < int, int > mp;
for(int i = 1; i <= n; i++){
cin >> a[i];
mp[a[i]] = i;
}
int ans = inf;
for(int msk = 0; msk < (1 << 20); msk++){
int cnt = 0;
bool x = 0;
int cur = 0;
for(int i = 1; i <= 20; i++){
if(msk & (1 << (i - 1))){
if(x == 0){
cnt++;
x = 1;
}
cur++;
}
else {
if(mp[i] != 0){
cnt = -1;
break;
}
if(x == 1){
x = 0;
}
}
}
if(cnt != -1 && cnt <= k){
ans = min(ans, cur);
}
}
cout << ans;
}
signed main() {
gold;
//freopen("knight.in", "r", stdin);
//freopen("knight.out", "w", stdout);
int t = 1;
int tt = 0;
//cin >> t;
while (t--) {
tt++;
//cout << "Case " << tt << ":" << xa;
solve();
}
}
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |