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

时间:2014-04-29 09:18:46   收藏:0   阅读:412

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

mamicode.com,码迷
#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;
}
mamicode.com,码迷

 

Codeforces Round #243 (Div. 2) C. Sereja and Swaps,码迷,mamicode.com

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!