Partial Sum

 
Accepted : 87   Submit : 366
Time Limit : 3000 MS   Memory Limit : 65536 KB

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 -1
4 2 1
-1 2 2 -1
4 2 2
-1 2 2 -1
4 2 10
-1 2 2 -1

Sample Output

3
4
2
0

解题思路:从0~n中选两个位置,例如3和7,那么 ans=ans+(a4+a5+a6+a7)-C,一直这样进行m次选取求最大的和

每次将其前缀和用一个数组存起来,那么a4+a5+a6+a7=sum[7]-sum[3]

对数组前缀和进行一次排序,,然后取m次那么就是其最大值

比赛的时候,没点到怎么优化,怎么交都是超时。。亏大发了

代码如下:

#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <vector>
#define LL __int64
using namespace std;
const int maxn=100005;
LL sum[maxn];
int main()
{int n,m,c,a;while(scanf("%d %d %d",&n,&m,&c)!=EOF){sum[0]=0;for(int i=1;i<=n;i++){scanf("%d",&a);sum[i]=sum[i-1]+a;///用数组sum储存前缀和}LL ans=0;sort(sum,sum+1+n);for(int i=0;i<m;i++){int b=abs(sum[n-i]-sum[i])-c;if(b<=0) break;ans+=b;}printf("%I64d\n",ans);}return 0;
}

XTU 1264 Partial Sum 2017年“嘉杰信息杯” 中国大学生程序设计竞赛全国邀请赛(湖南)相关推荐

  1. xtu 1268 Strange Optimization 2017年“嘉杰信息杯” 中国大学生程序设计竞赛全国邀请赛(湖南)

    Strange Optimization Bobo is facing a strange optimization problem. Given  n,m , he is going to find ...

  2. XTU 1268 Strange Optimization 2017年“嘉杰信息杯” 中国大学生程序设计竞赛全国邀请赛(湖南)

    Strange Optimization   Accepted : 65   Submit : 286 Time Limit : 1000 MS   Memory Limit : 65536 KB S ...

  3. 2017年“嘉杰信息杯” 中国大学生程序设计竞赛全国邀请赛 Partial Sum

    Partial Sum Accepted : 124   Submit : 450 Time Limit : 3000 MS   Memory Limit : 65536 KB  Partial Su ...

  4. 2017年“嘉杰信息杯” 中国大学生程序设计竞赛全国邀请赛:E—Partial Sum

    题目链接:传送门 Partial Sum Bobo has a integer sequence  a1,a2,-,an  of length  n . Each time, he selects t ...

  5. 2017年“嘉杰信息杯” 中国大学生程序设计竞赛全国邀请赛 Highway

    Highway Accepted : 122   Submit : 393 Time Limit : 4000 MS   Memory Limit : 65536 KB Highway In ICPC ...

  6. 2017年“嘉杰信息杯” 中国大学生程序设计竞赛全国邀请赛(湖南) 暨 第九届湘潭市大学生程序设计比赛H.Highway(树的直径)

    Highway Accepted : 122   Submit : 393 Time Limit : 4000 MS   Memory Limit : 65536 KB Highway In ICPC ...

  7. 2017年“嘉杰信息杯” 中国大学生程序设计竞赛全国邀请赛 Strange Optimization

    Strange Optimization Accepted : 89   Submit : 350 Time Limit : 1000 MS   Memory Limit : 65536 KB  St ...

  8. 2017年“嘉杰信息杯” 中国大学生程序设计竞赛全国邀请赛:H—Highway

    题目链接:http://202.197.224.59/OnlineJudge2/index.php/Problem/read/id/1267 Highway In ICPCCamp there wer ...

  9. 2017年“嘉杰信息杯” 中国大学生程序设计竞赛全国邀请赛:I— Strange Optimization

    题目链接:传送门 Strange Optimization Bobo is facing a strange optimization problem. Given  n,m , he is goin ...

最新文章

  1. 年底了,没啥好送的,送个1T移动硬盘吧~
  2. 信息哲学给哲学带来根本性革命了吗
  3. 问:一行Python代码到底能干多少事情?(三)
  4. kdevelp 导入makefile工程
  5. linux centos7使用,linux之centos7防火墙基本使用
  6. 触发键盘_雷蛇这款光轴机械键盘开箱评测,光速触发,颜值爆表
  7. beetl模板引擎之自定义html标签,Beetl模板引擎自定义分页标签
  8. 探究 Linux 内核 dts 设备树定义文件
  9. matlab设置ga算法,matlab遗传算法ga函数
  10. 传输层的端口与TCP标志中的URG和PSH位
  11. 遇到系统问题,先看OS再看CPU
  12. 第9节-做网站有哪些收入接入点
  13. c花体复制_能复制的花体英文字母
  14. 如何调整硬盘分区大小
  15. 电脑开启麦克风有回音,录音声音太小怎么办?
  16. 安然公司特殊目的实体(SPEs)解读
  17. 【Linux基础编程】help命令
  18. 【工具使用系列】关于 MATLAB Simulink 物理建模,你需要知道的事
  19. 在剪贴板上有大量信息,是否保留其内容, 以便此后粘贴到其他程序中? VBA 对策
  20. 迷室3第三章难点问题解读

热门文章

  1. 爱丽舍节油秘笈完全手册
  2. 第五九八章 全息头盔出问题了
  3. P5555 秩序魔咒
  4. 计算机网络--应用层-应用层协议原理
  5. pdf预览引发的vue项目只允许Chrome浏览器访问
  6. Markdown常识
  7. 小满OKKICRM与金蝶云星空对接集成客户列表查询客户新增
  8. docker buildx 构建arm64架构镜像
  9. 香橙派OrangePi Zero 装HomeAssistant (一)
  10. 文本分类(二) | (1) 项目介绍