#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ff first
#define ss second
#define pb push_back
#define meta int tm = (tl + tr) / 2, x = i * 2 + 1, y = x + 1
const int N = 2e5 + 7;
const int oo = 1e18;
const int mod = 1e9 + 7;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vii;
int n, k, mn = oo, a[N];
void rec (int i, int cnt, int mx, int ans) {
mx = max (mx, a[i]);
// cout << i << ' ' << cnt << ' ' << mx << ' ' << ans << '\n';
if (i == n + 1 && cnt == 0) {
if (ans < mn) mn = ans;
return;
}
if (i + cnt > n + 1 || cnt == 0) return;
rec (i + 1, cnt, mx, ans);
rec (i + 1, cnt - 1, 0, ans + mx);
return;
}
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
cin >> n >> k;
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
rec (1, k, 0, 0);
cout << mn;
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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |