Partial Sum
Partial Sum |
||
| Accepted : 80 | Submit : 353 | |
| Time Limit : 3000 MS | Memory Limit : 65536 KB | |
Partial SumBobo 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. InputThe 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 .
OutputFor each test cases, output an integer which denotes the maximum. Sample Input4 1 1 Sample Output3 |
//题意,最多选 m 次区间的和的绝对值 - c 的值,要求和最大,且所有点最多选一次作为端点
//贪心题,只要把前缀和排序,每次选最大的,最小的,直到选出值为负数,或等于m次,即停止
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;
#define MX 100005
#define LL long long int n,m,c;
int num[MX];
LL sum[MX]; int main()
{
while(~scanf("%d%d%d",&n,&m,&c))
{
sum[]=;
for (int i=;i<=n;i++)
{
scanf("%d",&num[i]);
sum[i]=sum[i-]+num[i];
}
sort(sum,sum++n);
int l = ,r = n;
LL ans = ; while (l<m&&sum[r]-sum[l]>c)
{
ans+=abs(sum[r]-sum[l])-c;
l++,r--;
}
printf("%I64d\n",ans);
}
return ;
}
Partial Sum的更多相关文章
- NYOJ--927--dfs--The partial sum problem
/* Name: NYOJ--927--The partial sum problem Author: shen_渊 Date: 15/04/17 19:41 Description: DFS,和 N ...
- 2017-5-14 湘潭市赛 Partial Sum 给n个数,每次操作选择一个L,一个R,表示区间左右端点,该操作产生的贡献为[L+1,R]的和的绝对值-C。 0<=L<R<=n; 如果选过L,R这两个位置,那么以后选择的L,R都不可以再选择这两个位置。最多操作m次,求可以获得的 最大贡献和。
Partial Sum Accepted : Submit : Time Limit : MS Memory Limit : KB Partial Sum Bobo has a integer seq ...
- NYOJ 927 The partial sum problem 【DFS】+【剪枝】
The partial sum problem 时间限制:1000 ms | 内存限制:65535 KB 难度:2 描写叙述 One day,Tom's girlfriend give him a ...
- 部分和(partial sum)在算法求解中的作用
C++ 的 STL 库的 <numeric> 头文件的 partial_sum 函数已实现了对某一序列的 partial sum. partial_sum(first, last, des ...
- ACM题目————The partial sum problem
描述 One day,Tom’s girlfriend give him an array A which contains N integers and asked him:Can you choo ...
- The partial sum problem
算法:搜索 描述 One day,Tom's girlfriend give him an array A which contains N integers and asked him:Can yo ...
- nyoj 927 The partial sum problem(dfs)
描述 One day,Tom’s girlfriend give him an array A which contains N integers and asked him:Can you choo ...
- NYoj The partial sum problem(简单深搜+优化)
题目链接:http://acm.nyist.edu.cn/JudgeOnline/problem.php?pid=927 代码: #include <stdio.h> #include & ...
- XTU 1264 - Partial Sum - [2017湘潭邀请赛E题(江苏省赛)]
2017江苏省赛的E题,当时在场上看错了题目没做出来,现在补一下…… 题目链接:http://202.197.224.59/OnlineJudge2/index.php/Problem/read/id ...
随机推荐
- Docker使用国内镜像
vim /lib/systemd/system/docker.service ExecStart=/usr/bin/dockerd -H fd:// --registry-mirror=https:/ ...
- 你要相信你所做的一切对一个更美好的世界 Do have faith in what you are doing All for a better world
http://www.nowamagic.net/librarys/veda/detail/2502 Do have faith in what you are doing. 先不要往下看,试试品尝上 ...
- hibernate(jpa)中注解配置字段为主键
http://www.blogjava.net/ITdavid/archive/2009/02/25/256605.html 注解方式的主键配置 非自增字段为主键,注解annotation表示 ...
- C#绑定事件时使用匿名函数
当使用一些临时的函数 可以预知这些函数基本不会被复用时 可以使用匿名函数简化代码 public static void startCoupons() { //绑定一些事件 userGetCoupon ...
- Pushlet后台推送
1.Pushlet 是一个开源的 Comet 框架,Pushlet 使用了观察者模型:客户端发送请求,订阅感兴趣的事件:服务器端为每个客户端分配一个会话 ID 作为标记,事件源会把新产生的事件以多播的 ...
- 用Emit技术替代反射
之前在上篇博客说到用表达式来替代反射机制,可以获得较高的性能提升.这篇我们来说说用Emit技术来替代反射. System.Reflection.Emit命名空间类可用于动态发出Microsoft中间语 ...
- BEGINNING SHAREPOINT® 2013 DEVELOPMENT 第9章节--client对象模型和REST APIs概览 client对象模型API范围
BEGINNING SHAREPOINT® 2013 DEVELOPMENT 第9章节--client对象模型和REST APIs概览 client对象模型API范围 本章之前提到过. ...
- Apache Rewrite 规则详解
在开篇之前: 我想说这篇文章其实是我刚刚接触Rewrite的时候学习的文档,应属转载,但是在这里我不想写明原地址,原因是文章中大多数给出的配置命令经实验都是错误的.需要原文的可以在谷歌上搜索一下&qu ...
- Python3 range()函数
Python3 range() 函数用法 Python3 内置函数 Python3 range() 函数返回的是一个可迭代对象(类型是对象),而不是列表类型, 所以打印的时候不会打印列表. Pyth ...
- angularjs 可以加入html标签方法------ng-bind-html的用法总结(1)
本篇主要讲解angular中的$sanitize这个服务.此服务依赖于ngSanitize模块.(这个模块需要加载angular-sanitize.js插件) 要学习这个服务,先要了解另一个指令: n ...