xtu 1264 Partial Sum 2017湘潭邀请赛E
来源:互联网 发布:三菱plc模块化编程 编辑:程序博客网 时间:2024/06/04 18:10
Partial Sum
Bobo has a integer sequence a1,a2,…,an of length n. Each time, he selects two ends 0≤l<r≤n and add |∑rj=l+1aj|−C into a counter which is zero initially. He repeats the selection for at most m times.
If each end can be selected at most once (either as left or right), find out the maximum sum Bobo may have.
Input
The input contains zero or more test cases and is terminated by end-of-file. For each test case:
The first line contains three integers n, m, C. The second line contains n integers a1,a2,…,an.
- 2≤n≤105
- 1≤2m≤n+1
- |ai|,C≤104
- The sum of n does not exceed 106.
Output
For each test cases, output an integer which denotes the maximum.
Sample Input
4 1 1-1 2 2 -14 2 1-1 2 2 -14 2 2-1 2 2 -14 2 10-1 2 2 -1
Sample Output
3420
#include <stdio.h>#include <algorithm>#include <vector>#include <string.h>#include <queue>#include <cmath>using namespace std; #define ll __int64const int N=100005; int main(){ ll n,m,c,a,sum[N]; while(~scanf("%I64d %I64d %I64d",&n,&m,&c)) { sum[0]=0; for(int i=1; i<=n; i++) { scanf("%I64d",&a); sum[i]=sum[i-1]+a; } sort(sum,sum+n+1); int l=n,s=0; ll ans=0; for(int i=0; i<m; i++) { ll t=abs(sum[n-i]-sum[i])-c; if(t<=0) break; ans+=t; } printf("%I64d\n",ans); } return 0;}
阅读全文
0 0
- xtu 1264 Partial Sum 2017湘潭邀请赛E
- 2017ccpc全国邀请赛(湖南湘潭) E. Partial Sum(前缀和)
- Partial Sum (2017湘潭)
- Partial Sum(湘潭邀请赛E题(部分和问题))
- xtu 1266 Parentheses 2017湘潭邀请赛G
- XTU 1264 Partial Sum 2017年“嘉杰信息杯” 中国大学生程序设计竞赛全国邀请赛(湖南)
- XTU 1264 Partial Sum 2017年“嘉杰信息杯” 中国大学生程序设计竞赛全国邀请赛(湖南)
- 2017湘潭赛Partial Sum
- XTU 1264 Partial Sum【思维+贪心】
- 2016湘潭邀请赛 XTU 1243 2016
- xtu 1267 Highway 湘潭邀请赛H
- xtu 1268 Strange Optimization 湘潭邀请赛I
- xtu 1268 Strange Optimization 湘潭邀请赛I
- 2017年“嘉杰信息杯” 中国大学生程序设计竞赛全国邀请赛:E—Partial Sum
- XTU 1264 Partial Sum 【思维 + 前缀和排序】
- 【XTU】2016湘潭邀请赛 I Substring Query【AC自动机+分块】
- 2016湘潭邀请赛 xtu 1243 矩阵快速幂
- 2015湘潭邀请赛 E.Magic Triangle
- return可以返回基本类型的局部变量,但是不可以返回指针
- 简单的ListView中的条目展示设置
- https服务,但是Spring MVC总是重定向到http,怎么才能使其重定向到https上
- vxWork内核解读三--调度器
- 飘雪轩ANGULAR2笔记
- xtu 1264 Partial Sum 2017湘潭邀请赛E
- redis3.0集群搭建
- Regionals 2011 >> Asia
- (转)Mysql通过命令授于用户数据库操作权限
- oracle dblink的创建和使用
- Redis集群搭建
- 关于Java 后台 手机号 、邮箱、 身份证 验证
- ORB-SLAM2的LOCAL MAPPING代码阅读
- vxWorks内核解读四--中断