#include <bits/stdc++.h>
#define maxn 205
#define MOD 1000000007
using namespace std;
typedef long long ll;
int n, k;
int num[maxn];
multiset<int> s1, s2;
int main(){
// freopen("in.txt", "r", stdin);
scanf("%d%d", &n, &k);
for(int i = 0; i < n; i++)
scanf("%d", num+i);
int ans = -100000000, sum;
set<int> ::iterator iter1, iter2;
for(int i = 0; i < n; i++){
s1.clear();
s2.clear();
sum = 0;
for(int j = 0; j < n; j++)
s2.insert(num[j]);
for(int j = i; j < n; j++){
sum += num[j];
s1.insert(num[j]);
iter2 = s2.lower_bound(num[j]);
s2.erase(iter2);
int m = k, p = sum;
iter1 = s1.begin();
if(s2.empty()){
ans = max(sum, ans);
break;
}
iter2 = --s2.end();
while(m-- && iter1 != s1.end()){
if(*iter1 < *iter2){
if(iter2 == s2.begin())
m = 0;
p += *iter2 - *iter1;
iter1++;
iter2--;
}
else break;
}
ans = max(ans, p);
}
}
printf("%d\n", ans);
return 0;
}
Codeforces Round #243 (Div. 2)-C. Sereja and Swaps(multiset)
最新推荐文章于 2024-07-08 09:59:31 发布