XTU 1264 Partial Sum 2017年“嘉杰信息杯” 中国大学生程序设计竞赛全国邀请赛(湖南)
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年“嘉杰信息杯” 中国大学生程序设计竞赛全国邀请赛(湖南)相关推荐
- xtu 1268 Strange Optimization 2017年“嘉杰信息杯” 中国大学生程序设计竞赛全国邀请赛(湖南)
Strange Optimization Bobo is facing a strange optimization problem. Given n,m , he is going to find ...
- XTU 1268 Strange Optimization 2017年“嘉杰信息杯” 中国大学生程序设计竞赛全国邀请赛(湖南)
Strange Optimization Accepted : 65 Submit : 286 Time Limit : 1000 MS Memory Limit : 65536 KB S ...
- 2017年“嘉杰信息杯” 中国大学生程序设计竞赛全国邀请赛 Partial Sum
Partial Sum Accepted : 124 Submit : 450 Time Limit : 3000 MS Memory Limit : 65536 KB Partial Su ...
- 2017年“嘉杰信息杯” 中国大学生程序设计竞赛全国邀请赛:E—Partial Sum
题目链接:传送门 Partial Sum Bobo has a integer sequence a1,a2,-,an of length n . Each time, he selects t ...
- 2017年“嘉杰信息杯” 中国大学生程序设计竞赛全国邀请赛 Highway
Highway Accepted : 122 Submit : 393 Time Limit : 4000 MS Memory Limit : 65536 KB Highway In ICPC ...
- 2017年“嘉杰信息杯” 中国大学生程序设计竞赛全国邀请赛(湖南) 暨 第九届湘潭市大学生程序设计比赛H.Highway(树的直径)
Highway Accepted : 122 Submit : 393 Time Limit : 4000 MS Memory Limit : 65536 KB Highway In ICPC ...
- 2017年“嘉杰信息杯” 中国大学生程序设计竞赛全国邀请赛 Strange Optimization
Strange Optimization Accepted : 89 Submit : 350 Time Limit : 1000 MS Memory Limit : 65536 KB St ...
- 2017年“嘉杰信息杯” 中国大学生程序设计竞赛全国邀请赛:H—Highway
题目链接:http://202.197.224.59/OnlineJudge2/index.php/Problem/read/id/1267 Highway In ICPCCamp there wer ...
- 2017年“嘉杰信息杯” 中国大学生程序设计竞赛全国邀请赛:I— Strange Optimization
题目链接:传送门 Strange Optimization Bobo is facing a strange optimization problem. Given n,m , he is goin ...
最新文章
- 年底了,没啥好送的,送个1T移动硬盘吧~
- 信息哲学给哲学带来根本性革命了吗
- 问:一行Python代码到底能干多少事情?(三)
- kdevelp 导入makefile工程
- linux centos7使用,linux之centos7防火墙基本使用
- 触发键盘_雷蛇这款光轴机械键盘开箱评测,光速触发,颜值爆表
- beetl模板引擎之自定义html标签,Beetl模板引擎自定义分页标签
- 探究 Linux 内核 dts 设备树定义文件
- matlab设置ga算法,matlab遗传算法ga函数
- 传输层的端口与TCP标志中的URG和PSH位
- 遇到系统问题,先看OS再看CPU
- 第9节-做网站有哪些收入接入点
- c花体复制_能复制的花体英文字母
- 如何调整硬盘分区大小
- 电脑开启麦克风有回音,录音声音太小怎么办?
- 安然公司特殊目的实体(SPEs)解读
- 【Linux基础编程】help命令
- 【工具使用系列】关于 MATLAB Simulink 物理建模,你需要知道的事
- 在剪贴板上有大量信息,是否保留其内容, 以便此后粘贴到其他程序中? VBA 对策
- 迷室3第三章难点问题解读