Codeforces Round #243 (Div. 2) C. Sereja and Swaps

由于n比较小,直接暴力解决

#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include<iterator>
using namespace std;

int main(){
    int n,k;
    cin >> n >> k;
    vector<int> a(n);
    for(int  i = 0 ; i < n;  ++ i) cin >> a[i];
    int sum = accumulate(a.begin(),a.end(),0);
    for(int i = 0 ; i < n; ++ i){
        for(int j = i ; j < n ; ++ j ){
            vector<int> tmp(a.begin()+i,a.begin()+j+1);
            sort(tmp.begin(),tmp.end());
            if(j-i+1!=n){
                vector<int> b(a);
                b.erase(b.begin()+i,b.begin()+j+1);
                sort(b.begin(),b.end(),greater<int>());
                for(int x =0, y = 0; b[x]>tmp[y] && x < k && x < b.size(); ++x ,++y){
                    tmp[y] = b[x];
                }
            }
            sum = max(sum,accumulate(tmp.begin(),tmp.end(),0));
        }
    }
    cout<<sum<<endl;
}

 

posted @ 2014-04-29 09:28  OpenSoucre  阅读(165)  评论(0编辑  收藏  举报