#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();
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
7 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
7 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Execution timed out |
1008 ms |
344 KB |
Time limit exceeded |
11 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
7 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Execution timed out |
1008 ms |
344 KB |
Time limit exceeded |
11 |
Halted |
0 ms |
0 KB |
- |