You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
24 lines
486 B
24 lines
486 B
#include <bits/stdc++.h>
|
|
using namespace std;
|
|
const int N = 100;
|
|
int a[N];
|
|
int n, k, res;
|
|
|
|
void dfs(int u, int k, int last, int sum) {
|
|
if (k == 0) {
|
|
res = max(res, sum);
|
|
return;
|
|
}
|
|
if (u == n + 1) return;
|
|
|
|
if (a[u] >= last)
|
|
dfs(u + 1, k - 1, a[u], sum + a[u]);
|
|
dfs(u + 1, k, last, sum);
|
|
}
|
|
int main() {
|
|
cin >> n >> k;
|
|
for (int i = 1; i <= n; i++) cin >> a[i];
|
|
dfs(1, k, 0, 0);
|
|
cout << res;
|
|
return 0;
|
|
} |