Codeforces Gym 100513F F. Ilya Muromets 水题
F. Ilya Muromets
Time Limit: 20 Sec
Memory Limit: 256 MB
题目连接
http://codeforces.com/gym/100513/problem/F
Description
I
Ilya Muromets is a legendary bogatyr. Right now he is struggling against Zmej Gorynych, a dragon with n heads numbered from 1 to nfrom left to right.
Making one sweep of sword Ilya Muromets can cut at most k contiguous heads of Zmej Gorynych. Thereafter heads collapse getting rid of empty space between heads. So in a moment before the second sweep all the heads form a contiguous sequence again.
As we all know, dragons can breathe fire. And so does Zmej Gorynych. Each his head has a firepower. The firepower of the i-th head isfi.
Ilya Muromets has time for at most two sword sweeps. The bogatyr wants to reduce dragon's firepower as much as possible. What is the maximum total firepower of heads which Ilya can cut with at most two sword sweeps?
Input
The first line contains a pair of integer numbers n and k (1 ≤ n, k ≤ 2·105) — the number of Gorynych's heads and the maximum number of heads Ilya can cut with a single sword sweep. The second line contains the sequence of integer numbers f1, f2, ..., fn(1 ≤ fi ≤ 2000), where fi is the firepower of the i-th head.
Output
Print the required maximum total head firepower that Ilya can cut.
Sample Input
8 2
1 3 3 1 2 3 11 1
Sample Output
20
HINT
题意
一个人可以砍两刀,每刀可以消去连续的K个数,然后问你两刀最多能砍下数的和是多少
题解:
这个我们枚举第一次砍的位置的左端点,并记为i,则贡献即为sum[i,i+k-1]+max[i+1,n];
其中sum[i,i+k-1]就是i到i+k-1的和,max[i+1,n]就是第一刀砍在i+1,n区间里所获得的最大值。
然后用个前缀和,再倒着扫一遍,求max数组就没了。
代码
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define N 200050
int n,k,kk,ans,a[N],s[N],mx[N];
template<typename T>void read(T&x)
{
ll k=; char c=getchar();
x=;
while(!isdigit(c)&&c!=EOF)k^=c=='-',c=getchar();
if (c==EOF)exit();
while(isdigit(c))x=x*+c-'',c=getchar();
x=k?-x:x;
}
void read_char(char &c)
{while(!isalpha(c=getchar())&&c!=EOF);}
int main()
{
#ifndef ONLINE_JUDGE
freopen("aa.in","r",stdin);
#endif
read(n); read(k);
kk=min(n,*k);
k=min(n,k);
for(int i=;i<=n;i++)read(a[i]),s[i]=a[i]+s[i-];
for(int i=n;i>=;i--)
{
int tp=s[min(n,i+k-)]-s[i-];
mx[i]=max(mx[i+],tp);
if (i+k-<=n)ans=max(ans,tp+mx[i+k]);
}
printf("%d",ans);
}
Codeforces Gym 100513F F. Ilya Muromets 水题的更多相关文章
- Codeforces Gym 100513F F. Ilya Muromets 线段树
F. Ilya Muromets Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100513/probl ...
- codeforces Gym 100187H H. Mysterious Photos 水题
H. Mysterious Photos Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100187/p ...
- codeforces Gym 100500H H. ICPC Quest 水题
Problem H. ICPC QuestTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100500/a ...
- Codeforces Gym 100269A Arrangement of Contest 水题
Problem A. Arrangement of Contest 题目连接: http://codeforces.com/gym/100269/attachments Description Lit ...
- Codeforces Gym 100269B Ballot Analyzing Device 模拟题
Ballot Analyzing Device 题目连接: http://codeforces.com/gym/100269/attachments Description Election comm ...
- Educational Codeforces Round 7 B. The Time 水题
B. The Time 题目连接: http://www.codeforces.com/contest/622/problem/B Description You are given the curr ...
- Educational Codeforces Round 7 A. Infinite Sequence 水题
A. Infinite Sequence 题目连接: http://www.codeforces.com/contest/622/problem/A Description Consider the ...
- codeforces 677A A. Vanya and Fence(水题)
题目链接: A. Vanya and Fence time limit per test 1 second memory limit per test 256 megabytes input stan ...
- Codeforces Testing Round #12 A. Divisibility 水题
A. Divisibility Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/597/probl ...
随机推荐
- WPF DataGrid实现分页显示
主要代码如下 /// <summary> /// 读取指定页面的数据 /// </summary> /// <param name="pagePerCount& ...
- mybatis 2 -常用数据操作
1.写入数据并获取自增ID XML配置: <!-- 写入数据获取自增ID --> <insert id="insertLog" parameterType=&qu ...
- leetcode111
/** * Definition for a binary tree node. * public class TreeNode { * public int val; * public TreeNo ...
- Git---时光穿梭机之版本回退02
现在你的本地仓库底下添加一个readme.txt文件 第一次readme.txt的内容如下:: Git is a version control systemGit is free sofwore 然 ...
- tomcat没有发布maven项目依赖的本地jar包
建立springMVC的maven项目,平时使用的jar包都是在pom.xml文件配置依赖关系, maven会自动从仓库中下载,这样使用tomcat部署发布都没有问题.但有时我们需要使用maven仓库 ...
- inotify监测实例
/************************************************************************* > File Name: inotify.c ...
- 记一次为gitlab启用CI的过程
问题描述: 在局域网内搭了了一个gitlab,最近有需求要用CI 那时我不在 ,他们尝试了一段时间的Jenkins,但是还没有成功,我说gitlab已经有这些功能了,不用那个.于是一个人搞起来了. 从 ...
- 在Ubuntu16.04中安装Docker CE
apt-get install apt-transport-https ca-certificates curl software-properties-common curl -fsSL https ...
- 新手C#异常的学习2018.08.07
异常是在程序执行期间出现的问题.C# 中的异常是对程序运行时出现的特殊情况的一种响应,比如尝试除以零. class Program { static void Main(string[] args) ...
- (转)Java 中关于String的空对象(null) ,空值(empty),空格
原文出处:Java 中关于String的空对象(null) ,空值(empty),空格 定义 空对象: String s = null; 空对象是指定义一个对象s,但是没有给该对象分配空间,即没有实例 ...