This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define vt vector
#define nl " \n"
#define pb emplace_back
#define all(x) x.begin(), x.end()
template <class F, class S>
void chmin(F &a, S b) {
if(a > b) a = b;
}
template <class F, class S>
void chmax(F &a, S b) {
if(a < b) a = b;
}
void run_case() {
int n, k;
cin >> n >> k;
vt<int> a(n);
for(auto &i : a) {
cin >> i;
}
auto Brute = [&](){
int ans = *max_element(all(a));
for(int mask = 0; mask < (1 << n); mask++) {
if(mask % 2 == 0 || __builtin_popcount(mask) != k) continue;
int tot = 0, j = 0, mx = 0;
for(int i = 0; i < n; i++) {
if(mask >> i & 1) {
tot += mx;
mx = 0;
j = i;
}
chmax(mx, a[i] - a[j] + 1);
}
chmin(ans, tot + mx);
}
return ans;
};
cout << Brute() << nl;
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int tt = 1;
// cin >> tt;
for(int i = 0; i < tt; i++) {
run_case();
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |