2017湘潭赛XTU1264Partial Sum
2017-07-13 11:27
253 查看
| ||
Accepted : 155 | Submit : 567 | |
Time Limit : 3000 MS | Memory Limit : 65536 KB |
Partial SumBobo has a integer sequence a1,a2,…,an oflength 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. The input contains zero or more test cases and is terminated by end-of-file. For each test case: |
想求出前缀和 选择连个端点然后累加 相当于两个前缀和相减
问题想当与 选多对前缀和相减值再相加 和最大
先将前缀和排序 然后最大减最小 第二大减第二小...................
#include<stdio.h> #include<string.h> #include<iostream> #include<algorithm> using namespace std; #define ll __int64 ll a[150000]; ll sum[150000]; int main() { int n,m; ll C; while(~scanf("%d%d%I64d",&n,&m,&C)) { for(int i=1;i<=n;i++)scanf("%I64d",&a[i]); for(int i=1;i<=n;i++) { if(i==1)sum[i]=a[i]; sum[i]=sum[i-1]+a[i]; } sort(sum,sum+1+n); ll cnt=0; ll ans=0; for(int i=0;i<m;i++) { cnt+=(sum[n-i]-sum[i]-C); ans=max(ans,cnt); } printf("%I64d\n",ans); } return 0; }
相关文章推荐
- 2017 湘潭邀请赛 H Highway(树的直径)
- 2017湘潭赛总结
- 湘潭2017 ccpc中南地区邀请赛 Determinant 高斯约当求逆矩阵
- 2017 ccpc 湘潭邀请赛 H highway
- 2017湘潭赛Partial Sum
- xtu 1264 Partial Sum 2017湘潭邀请赛E
- Xiangtan Invitation Contest 2017(2017湘潭邀请赛)(Done)
- xtu 1266 Parentheses 2017湘潭邀请赛G
- 2017湘潭赛XTU1266Parentheses
- 2017湘潭赛XTU1267Highway
- Partial Sum (2017湘潭)
- 湘潭邀请赛 2017 题解
- 2017湘潭赛 A题 Determinant (高斯消元取模)
- 阿里2017笔试(3)
- LF Asia 公布 2017 年度中国 LinuxCon + ContainerCon + CloudOpen 大会日程
- 斯坦福CS231n Spring 2017开放全部课程视频
- 【JZOJ5427】【NOIP2017提高A组集训10.25】吃草[1D1D优化]
- 企业智能化升级之路:CSDN《2017-2018中国人工智能产业路线图V1.0》重磅发布
- 2017系列(序):一系列佳作,喜迎2017
- 2017中国移动浙江分公司暑期实习生面试及秋招坑爹后续