http://codeforces.com/contest/426/problem/C

题意:找出连续序列的和的最大值,可以允许交换k次任意位置的两个数。

思路:枚举区间,依次把区间内的比较小的数换成区间外的比较大的数。

 #include <cstdio>
#include <iostream>
#include <cstring>
#include <queue>
#include <algorithm>
using namespace std; int a[],b[],c[];
int n,kk;
bool cmp(int aa,int bb)
{
return aa>bb;
} int main()
{
cin>>n>>kk;
int ans=-;
for(int i=; i<=n; i++)
{
cin>>a[i];
ans=max(ans,a[i]);
}
for(int i=; i<=n; i++)
{
for(int j=i+; j<=n; j++)
{
int t=;
memset(b,,sizeof(b));
memset(c,,sizeof(c));
for(int k=i; k<=j; k++)
{
b[t++]=a[k];
}
int t1=;
for(int x=; x<i; x++)
{
c[t1++]=a[x];
}
for(int x=j+; x<=n; x++)
{
c[t1++]=a[x];
}
sort(b,b+t);
sort(c,c+t1,cmp);
int sum=;
for(int x=; x<=min(kk,t); x++)
{
if(b[x-]<c[x-]&&x<=t1)
{
sum+=c[x-];
}
else
sum+=b[x-];
}
for(int x=min(kk,t); x<t; x++)
{
sum+=b[x];
}
ans=max(ans,sum);
}
}
printf("%d\n",ans);
return ;
}

最新文章

  1. Huffman树进行编码和译码
  2. InfluxDB学习之InfluxDB的HTTP API查询操作
  3. 亿级Web系统搭建——单机到分布式集群
  4. PHP高效率写法
  5. Effective Java 06 Eliminate obsolete object references
  6. node.js安装及grunt插件,如何进行脚本压缩
  7. 什么是HotSpot VM &amp; 深入理解Java虚拟机
  8. Flex之DataGrid和Tree控件的数据源XML格式
  9. 不要停留在表面,MVC 3 我们要深入一些
  10. google python/c++ code style naming
  11. Using Ninject in a Web Application
  12. apache的.htaccess文件作用和相关配置
  13. .NET工行E生活接入AES加密算法的吐槽-2018
  14. Spring的后处理器-BeanPostProcessor跟BeanFactoryPostProcessors
  15. tomcat 端口修改和内存配置
  16. Java获取当前时间的年月日方法
  17. TMS WEB Core v1.2预览版:新的Electron应用程序支持
  18. MySQL 分区间进行数据展示 实例
  19. try cache
  20. Python Socket传输文件

热门文章

  1. bt 介绍以及 bt 种子的hash值(特征值)计算
  2. PHP面向对象之旅:抽象类继承抽象类(转)
  3. 【Linux学习笔记】用nc实现两台主机间的文件传输(不需要输密码)
  4. [转] nginx 开启gzip压缩--字符串压缩比率很牛叉
  5. iOS UIKit:Auto Layout
  6. unity介绍
  7. 【Android】android镜像翻转
  8. codevs 3119 高精度练习之大整数开根 (各种高精+压位)
  9. HTTP could not register URL http://+:8000/.... Your process does not have access rights to this namespace
  10. godaddy_关于产品退款