Codeforces Gym 100513F F. Ilya Muromets 水题

时间:2022-09-30 14:06:57

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 水题的更多相关文章

  1. Codeforces Gym 100513F F&period; Ilya Muromets 线段树

    F. Ilya Muromets Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100513/probl ...

  2. codeforces Gym 100187H H&period; Mysterious Photos 水题

    H. Mysterious Photos Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100187/p ...

  3. codeforces Gym 100500H H&period; ICPC Quest 水题

    Problem H. ICPC QuestTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100500/a ...

  4. Codeforces Gym 100269A Arrangement of Contest 水题

    Problem A. Arrangement of Contest 题目连接: http://codeforces.com/gym/100269/attachments Description Lit ...

  5. Codeforces Gym 100269B Ballot Analyzing Device 模拟题

    Ballot Analyzing Device 题目连接: http://codeforces.com/gym/100269/attachments Description Election comm ...

  6. Educational Codeforces Round 7 B&period; The Time 水题

    B. The Time 题目连接: http://www.codeforces.com/contest/622/problem/B Description You are given the curr ...

  7. Educational Codeforces Round 7 A&period; Infinite Sequence 水题

    A. Infinite Sequence 题目连接: http://www.codeforces.com/contest/622/problem/A Description Consider the ...

  8. codeforces 677A A&period; Vanya and Fence&lpar;水题&rpar;

    题目链接: A. Vanya and Fence time limit per test 1 second memory limit per test 256 megabytes input stan ...

  9. Codeforces Testing Round &num;12 A&period; Divisibility 水题

    A. Divisibility Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/597/probl ...

随机推荐

  1. cursor&colon;pointer

    .cursor_hand{ cursor:pointer; }

  2. ZOJ 3545 Rescue the Rabbit(AC自动机&plus;状压DP)(The 2011 ACM-ICPC Asia Dalian Regional Contest)

    Dr. X is a biologist, who likes rabbits very much and can do everything for them. 2012 is coming, an ...

  3. Linux系统查看系统是32位还是64位方法总结【转】

    转自:http://www.cnblogs.com/kerrycode/p/3785768.html 这篇博客是总结.归纳查看Linux系统是32位还是64位的一些方法,很多内容来自网上网友的博客.本 ...

  4. C&num;中多线程写DataGridView出现滚动条导致程序卡死(无响应)的解决办法

    因为写的程序涉及到多线程维护一个DataGridView,然后蛋疼的发现经常卡死...一开始以为是读写冲突的原因,然后就加了锁,问题依旧...然后发现每次出现滚动条的时候程序才会无响应,所以感觉应该是 ...

  5. &lpar;转载&rpar;MVC &plus; JQUERY &plus; AJAX的几种方式

    MVC + JQUERY + AJAX的几种方式 // 传过去一个简单值,获取一个简单值 $.ajax({            type: "GET",         url: ...

  6. java基础(二十)IO流(三)

    这里有我之前上课总结的一些知识点以及代码大部分是老师讲的笔记 个人认为是非常好的,,也是比较经典的内容,真诚的希望这些对于那些想学习的人有所帮助! 由于代码是分模块的上传非常的不便.也比较多,讲的也是 ...

  7. discuz X3&period;1的门户文章实现伪静态,利于搜索引擎收录url的地址修改

    最近在捣鼓DZ框架,这两天发现文章的收录情况并不是太理想,做了很多优化方面的工作,今天主要解决了DZ门户的文章链接伪静态化,在这次修改之前,也做过一次在网上找的静态化修改,之前做的方式是: 1.在DZ ...

  8. SpringMvc4&period;x--&commat;ControllerAdvice注解

    通过@ControllerAdvice.我们可以将对于控制器的全局配置放置在同一个位置,注解了@ControllerAdvice的类的方法可以使用@ExceptionHandler,@InitBind ...

  9. 从&OpenCurlyDoubleQuote;跳一跳”来看微信小程序的未来

    从“跳一跳”来看微信小程序的未来   相信大家这两天都被微信新推出的小程序跳一跳刷爆了朋友圈,为了方便用户在使用过程中切换小程序,微信在这次6.6.1版本中加入了下拉可快速切换小程序的功能,而“跳一跳 ...

  10. hadoop 2&period;x 简单实现wordCount

    简单实现hadoop程序,包括:hadoop2.x的实现写法 import org.apache.hadoop.conf.Configured; import org.apache.hadoop.fs ...