A. Sereja and Swaps
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

As usual, Sereja has array a, its elements are integers: a[1], a[2], ..., a[n]. Let's introduce notation:

A swap operation is the following sequence of actions:

  • choose two indexes i, j (i ≠ j);
  • perform assignments tmp = a[i], a[i] = a[j], a[j] = tmp.

What maximum value of function m(a) can Sereja get if he is allowed to perform at most k swap operations?

Input

The first line contains two integers n and k (1 ≤ n ≤ 200; 1 ≤ k ≤ 10). The next line contains n integers a[1], a[2], ..., a[n] ( - 1000 ≤ a[i] ≤ 1000).

Output

In a single line print the maximum value of m(a) that Sereja can get if he is allowed to perform at most k swap operations.

Sample test(s)
Input
10 2
10 -1 2 2 2 2 2 2 -1 10
Output
32
Input
5 10
-1 -1 -1 -1 -1
Output
-1

题意:给你一串数列,允许换K次位置,然后让你求一个最大的连续和
题解:暴力枚举区间就是!
int a[maxn];
vector<int>kiss;
vector<int>miss;
int main()
{
int n,m,ans,i,j,k;
while(cin>>n>>m)
{
for(i=;i<=n;i++)
scanf("%d",&a[i]);
ans=-inf;
for(i=;i<=n;i++)
{
int sum=;
for(j=i;j<=n;j++)
{
kiss.clear();
miss.clear();
sum=;
for(k=i;k<=j;k++)
{
kiss.push_back(a[k]);
sum+=a[k];
}
for(k=;k<=n;k++)
{
if(k<i||k>j)
miss.push_back(a[k]);
}
sort(kiss.begin(),kiss.end());
sort(miss.begin(),miss.end());
ans=max(ans,sum);
for(k=;k<=m&&k<=kiss.size()&&k<=miss.size();k++)
{
sum-=kiss[k-];
sum+=miss[miss.size()-k];
ans=max(ans,sum);
}
}
}
cout<<ans<<endl;
}
return ;
}

Codeforces Round #243 (Div. 1)A. Sereja and Swaps 暴力的更多相关文章

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

    由于n比较小,直接暴力解决 #include <iostream> #include <vector> #include <algorithm> #include ...

  2. Codeforces Round #243 (Div. 2) C. Sereja and Swaps(优先队列 暴力)

    题目 题意:求任意连续序列的最大值,这个连续序列可以和其他的 值交换k次,求最大值 思路:暴力枚举所有的连续序列.没做对是因为 首先没有认真读题,没看清交换,然后,以为是dp或者贪心 用了一下贪心,各 ...

  3. Codeforces Round #243 (Div. 2) B. Sereja and Mirroring

    #include <iostream> #include <vector> #include <algorithm> using namespace std; in ...

  4. Codeforces Round #243 (Div. 2) A. Sereja and Mugs

    #include <iostream> #include <vector> #include <algorithm> #include <numeric> ...

  5. Codeforces Round #297 (Div. 2)D. Arthur and Walls 暴力搜索

    Codeforces Round #297 (Div. 2)D. Arthur and Walls Time Limit: 2 Sec  Memory Limit: 512 MBSubmit: xxx ...

  6. Codeforces Round #243 (Div. 2) A~C

    题目链接 A. Sereja and Mugs time limit per test:1 secondmemory limit per test:256 megabytesinput:standar ...

  7. Codeforces Round #243 (Div. 2) Problem B - Sereja and Mirroring 解读

    http://codeforces.com/contest/426/problem/B 对称标题的意思大概是.应当指出的,当线数为奇数时,答案是线路本身的数 #include<iostream& ...

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

    版权声明:本文为博主原创文章,未经博主同意不得转载. https://blog.csdn.net/u012476429/article/details/24665103 题目链接 题意: 给定一个整数 ...

  9. Codeforces Round #243 (Div. 2)——Sereja and Table

    看这个问题之前,能够先看看这个论文<一类算法复合的方法>,说白了就是分类讨论,可是这个思想非常重要 题目链接 题意: 首先给出联通块的定义:对于相邻(上下和左右)的同样的数字视为一个联通块 ...

随机推荐

  1. ASP防XSS代码

    原作是在GitHub上,基于Node.js所写.但是..ASP的JS引擎跟V8又有些不同..于是,嗯.. <% Function AntiXSS_VbsTrim(s) AntiXSS_VbsTr ...

  2. 32 Profiling Go Programs 分析go语言项目

    Profiling Go Programs  分析go语言项目 24 June 2011 At Scala Days 2011, Robert Hundt presented a paper titl ...

  3. Ubuntu 18.04安装MongoDB 4.0(社区版)

    Ubuntu 18.04(虚拟机VirtualBox上),MongoDB 4.0, 听室友说,23点有世界杯决赛呢!可是,孤要写博文的啊!以记录这忙乱的下午和晚间成功安装了一个软件到Linux上.—— ...

  4. Densely Connected Convolutional Networks 论文阅读

    毕设终于告一段落,传统方法的视觉做得我整个人都很奔溃,终于结束,可以看些搁置很久的一些论文了,嘤嘤嘤 Densely Connected Convolutional Networks 其实很早就出来了 ...

  5. HDU 1669 Jamie's Contact Groups(多重匹配+二分枚举)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1669 题目大意: 给你各个人可以属于的组,把这些人分组,使这些组中人数最多的组人数最少,并输出这个人数 ...

  6. Oracle 提示符

    http://blog.csdn.net/wyzxg/article/details/5647905

  7. Writing a Kernel in C++

    *:first-child { margin-top: 0 !important; } .markdown-body>*:last-child { margin-bottom: 0 !impor ...

  8. 一步一步学习IdentityServer4 (1) 概要配置说明

    //结合EFCore生成IdentityServer4数据库 // 项目工程文件最后添加 <ItemGroup><DotNetCliToolReference Include=&qu ...

  9. java8 - Optional

    mport java.util.Optional; import org.junit.Test; /* * 一.Optional 容器类:用于尽量避免空指针异常 * Optional.of(T t) ...

  10. centos7.x firewall简单使用

    开放一个端口: firewall-cmd --zone=public --add-port=22/tcp –permanent 开放一个范围端口对外部所有地址生效: firewall-cmd --zo ...