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 ...
随机推荐
- iOS学习笔记之蓝牙(有关蓝牙设备mac地址处理) 2
1.创建中心设备,并设置代理 一般情况下,手机是中心设备,蓝牙设备是外围设备. self.centralManager = [[CBCentralManager alloc] initWithDele ...
- [转载]Android开发者必须深入学习的10个应用开源项目
[转载]Android开发者必须深入学习的10个应用开源项目 原文地址:Android开发者必须深入学习的10个应用开源项目(http://blog.sina.com.cn/s/blog_7b8a63 ...
- Struts + Spring + Hibernate 进阶开端(一)
Long Long ago,就听说过SSH,起初还以为是一个东东,具体内容更是不详,总觉得高端大气上档次,经过学习之后才发现,不仅仅是高大上,更是低调奢华有内涵,经过一段时间的研究和学习SSH框架的基 ...
- JUnit4.8.2源码分析-1 说明
阅读本系列文章时须要知道的: JUnit是由GOF 之中的一个的Erich Gamma和 Kent Beck 编写的一个开源的单元測试框架,分析JUnit源码的主要目的是学习当中对设计模式的运用.JU ...
- 【Java】Java_11运算符
1.运算符(operator) Java 语言支持如下运算符: 算术运算符: +,-,*,/,%,++ 赋值运算符 = 关系运算符: >,<,>=,<=,==,!= i ...
- svn命令行版本回滚
下面以版本号2011回滚到2010为例,在命令行输入: svn merge --dry-run -r 2011:2010 http://my.repository.com/my/project/tru ...
- Intellij Idea 使用入门教程
1.安装Idea Download: http://www.jetbrains.com/idea/download/#section=windows (请下载UItimate) Lisense: ...
- SVN环境搭建(2)
原文地址:http://www.penglig.com/post-73.html TortoiseSVN的使用. 首先打开VisualSVN Server Manager,如图: 可以在窗口的右边看到 ...
- Web服务器性能/压力测试工具http_load、webbench、ab、Siege、loadrunner
回头看看 Web服务器性能/压力测试工具http_load.webbench.ab.Siege.loadrunner
- SpringCloud系列十:使用Feign实现声明式REST调用
1. 回顾 前文的示例中是使用RestTemplate实现REST API调用的,代码大致如下: @GetMapping("/user/{id}") public User fin ...