Codeforces 426C Sereja and Swaps【思维】
来源:互联网 发布:三星手机天气预报软件 编辑:程序博客网 时间:2024/06/05 04:43
题目大意:
给出长度为N的一个序列,我们现在可以交换一对数字最多K次,问交换之后,最大的连续子序列的和。
思路:
观察到n和k都不大 ,我们可以O(n^2)枚举出连续子序列和的区间【L,R】,然后将区间内最小的值,和区间外最大的值不断进行交换,维护最大值即可。
Ac代码:
#include<stdio.h>#include<string.h>#include<queue>using namespace std;int a[500];int main(){ int n,T; while(~scanf("%d%d",&n,&T)) { int output=-0x3f3f3f3f; for(int i=1;i<=n;i++)scanf("%d",&a[i]); for(int i=1;i<=n;i++) { for(int j=i;j<=n;j++) { priority_queue<int,vector<int>,less<int> >out; priority_queue<int,vector<int>,greater<int> >in; for(int k=1;k<=n;k++) { if(k>=i&&k<=j) { in.push(a[k]); } else out.push(a[k]); } int temp=T; while(temp--) { if(out.size()==0||in.size()==0)continue; int u=out.top(); int v=in.top(); if(u>v) { in.pop();out.pop(); out.push(v);in.push(u); } } int sum=0; while(!in.empty()) { int u=in.top(); sum+=u; in.pop(); } output=max(output,sum); } } printf("%d\n",output); }}
阅读全文
0 0
- Codeforces 426C Sereja and Swaps【思维】
- CF 426C--Sereja and Swaps
- Codeforces Round #243 (Div. 2) C. Sereja and Swaps
- Codeforces Round #243 (Div. 2) C. Sereja and Swaps
- Codeforces Round #243 (Div. 2)-C. Sereja and Swaps(multiset)
- Codeforces 368C Sereja and Algorithm【思维】
- Codeforces 315C Sereja and Contest【思维】
- CodeForces 425A Sereja and Swaps
- Codeforces 425A Sereja and Swaps(暴力)
- codeforces 425A Sereja and Swaps
- C. Sereja and Swaps/优先队列
- Codeforces Round #243 (Div. 2) C. Sereja and Swaps 解题报告
- Sereja and Swaps
- 【CodeForces】368C - Sereja and Algorithm(思维)
- Codeforces 381C Sereja and Brackets【二分+思维】好题~
- Codeforces 425A Sereja and Swaps(暴力枚举)
- Codeforces Round #243 (Div. 2)——Sereja and Swaps
- Codeforces 425A Sereja and Swaps(暴力+贪心)
- Entity Framework Core 2.0 新特性
- .NET Core 2.0 的dll实时更新、https、依赖包变更问题及解决
- C#使用Xamarin开发可移植移动应用(3.Xamarin.Views控件)附源码
- ASP.NET Core
- .NET Core 2.0使用NLog
- Codeforces 426C Sereja and Swaps【思维】
- 体验 PHP under .NET Core
- web-前端之登录界面
- .NET Standard 2.0 特性介绍和使用指南
- ASP.NET Core
- .NET Core 2.0 正式发布信息汇总
- ASP.NET Core 源码学习之Logging[1]:Introduction
- 如何在Linux上使用VIM进行.Net Core开发
- ASP.NET Core 快速入门(实战篇)