Lecture Sleep(前缀和)
Mishka is really interested in calculus, though it is so hard to stay awake for all the time of lecture. You are given an array t of Mishka's behavior. If Mishka is asleep during the i-th minute of the lecture then ti will be equal to 0, otherwise it will be equal to 1. When Mishka is awake he writes down all the theorems he is being told — ai during the i-th minute. Otherwise he writes nothing.
You know some secret technique to keep Mishka awake for k minutes straight. However you can use it only once. You can start using it at the beginning of any minute between 1 and n - k + 1. If you use it on some minute i then Mishka will be awake during minutes j such that
and will write down all the theorems lecturer tells.
You task is to calculate the maximum number of theorems Mishka will be able to write down if you use your technique only once to wake him up.
The first line of the input contains two integer numbers n and k (1 ≤ k ≤ n ≤ 105) — the duration of the lecture in minutes and the number of minutes you can keep Mishka awake.
The second line of the input contains n integer numbers a1, a2, ... an (1 ≤ ai ≤ 104) — the number of theorems lecturer tells during the i-th minute.
The third line of the input contains n integer numbers t1, t2, ... tn (0 ≤ ti ≤ 1) — type of Mishka's behavior at the i-th minute of the lecture.
Print only one integer — the maximum number of theorems Mishka will be able to write down if you use your technique only once to wake him up.
6 3
1 3 5 2 5 4
1 1 0 1 0 0
16
In the sample case the better way is to use the secret technique at the beginning of the third minute. Then the number of theorems Mishka will be able to write down will be equal to 16.
题解:我们根据样例输入来分析大意:我现在要去听一个6分钟的讲座,根据样例输入的第三行,我在第1、2、4分钟是醒着的,其他时间睡着了。其中有一种清醒手段能让我连续三分钟保持清醒(样例输入第一行第二个),例如在第1、2、3分钟使用这个手段,那么将改变我在第3分钟的状态(本来是0,代表睡着,现在由于使用了手段,于是醒了)。样例输入的第二行代表每分钟讲座会讲多少个数学定理,在醒着的时候我可以将定理全部记下来,然而在睡着的时候我无法记笔记。现在要求计算我最多能记多少笔记(在使用清醒手段的情况下)。
#include<stdio.h>
#include<string.h>
#include<stack>
#include<string.h>
#include<queue>
#include<algorithm>
#include<map>
#include<vector>
#define PI acos(-1.0)
using namespace std;
typedef long long ll;
#define Inf 0x3f3f3f3f
int m,n;
int str[];
int visit[];
int k[];
int dp[];
int di[][]= {{-,},{,},{,-},{,}};
map<ll,ll>::iterator it;
int main()
{
int i,j;
scanf("%d%d",&m,&n);
memset(dp,,sizeof(dp));
memset(k,,sizeof(k));
for(i=; i<=m; i++)
{
scanf("%d",&str[i]);
dp[i]=dp[i-]+str[i];//记录前n项和
}
int ans=-,p=-,kk=;
for(i=; i<=m; i++)
{
scanf("%d",&visit[i]);
if(visit[i])
kk=str[i];
else
kk=;
k[i]=k[i-]+kk;//记录非零前n项和
}
int sum=,ans1;
for(i=; i<=m-n+; i++)
{
ans1=dp[i+n-]-dp[i-]+sum+k[m]-k[i+n-]+k[i-];//枚举每一种情况(再第i分钟所获得的最大定理数)
ans=max(ans,ans1);
}
printf("%d\n",ans);
return ;
}
Lecture Sleep(前缀和)的更多相关文章
- [C2P3] Andrew Ng - Machine Learning
##Advice for Applying Machine Learning Applying machine learning in practice is not always straightf ...
- Lecture Sleep(尺取+前缀和)
Description 你的朋友Mishka和你参加一个微积分讲座.讲座持续n分钟.讲师在第i分钟讲述ai个定理. 米什卡真的对微积分很感兴趣,尽管在演讲的所有时间都很难保持清醒.给你一个米什卡行 ...
- Trie(前缀树/字典树)及其应用
Trie,又经常叫前缀树,字典树等等.它有很多变种,如后缀树,Radix Tree/Trie,PATRICIA tree,以及bitwise版本的crit-bit tree.当然很多名字的意义其实有交 ...
- HDU1671——前缀树的一点感触
题目http://acm.hdu.edu.cn/showproblem.php?pid=1671 题目本身不难,一棵前缀树OK,但是前两次提交都没有成功. 第一次Memory Limit Exceed ...
- 【手记】注意BinaryWriter写string的小坑——会在string前加上长度前缀length-prefixed
之前以为BinaryWriter写string会严格按构造时指定的编码(不指定则是无BOM的UTF8)写入string的二进制,如下面的代码: //将字符串"a"写入流,再拿到流的 ...
- ASP.NET Core MVC 配置全局路由前缀
前言 大家好,今天给大家介绍一个 ASP.NET Core MVC 的一个新特性,给全局路由添加统一前缀.严格说其实不算是新特性,不过是Core MVC特有的. 应用背景 不知道大家在做 Web Ap ...
- 如何处理CSS3属性前缀
今天闲来无聊,重新来说说CSS3前缀的问题.在春节前和@一丝姐姐说起Sass中有关于gradient的mixins.姐姐说: 为什么还要用mixin呢?为什么不使用Autoprefixer?使用Aut ...
- context:component-scan" 的前缀 "context" 未绑定。
SpElUtilTest.testSpELLiteralExpressiontestSpELLiteralExpression(cn.zr.spring.spel.SpElUtilTest)org.s ...
- 解决adobe air sdk打包 apk后自动在包名前面加上air. (有个点)前缀的问题
早就找到了这个方法,但是一直忙没心思写博客. 默认情况下,所有 AIR Android 应用程序的包名称都带 air 前缀.若不想使用此默认行为,可将计算机环境变量 AIR_NOANDROIDFLAI ...
随机推荐
- dateTimePicker编辑状态下,取值不正确的问题
当对dateTimePicker进行编辑,回车,调用函数处理dateTimePicker的value值时,其取值结果是你编辑之前的值,而不是你编辑后的值,虽然dateTimePicker.text的值 ...
- 读书笔记-Ribbon源码分析
@LoadBalanced注解用来给RestTemplate做标记,以使用负载均衡的客户端来配置. 通过搜索LoadBalancerClient可以发现,LoadBalancerClient是Spri ...
- jquery自定义插件实现分页效果
这节介绍如何自定义jquery插件,实现分页效果,话不多说,先看看实现的效果: 分页插件 实现的代码如下: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTM ...
- linux 压缩文件 上传下载 直接弹出
yum -y install lrzsz rz -y 上传 sz -y 下载 -y 是替换了直接,不加的话,如果目录下有同名文件,会提示
- kafka系列之(3)——Coordinator与offset管理和Consumer Rebalance
from:http://www.jianshu.com/p/5aa8776868bb kafka系列之(3)——Coordinator与offset管理和Consumer Rebalance 时之结绳 ...
- Window Handle介绍
HANDLE(句柄)是Windows操作系统中的一个概念.在Windows程序中,有各种各样的资源(窗口.图标.光标等),系统在创建这些资源时会为它们分配内存,并返回标示这些资源的标示号,即句柄.句柄 ...
- 《Troubleshooting SQL Server》读书笔记-内存管理
自调整的数据库引擎(Self-tuning Database Engine) 长期以来,微软都致力于自调整(Self-Tuning)的SQL Server数据库引擎,用以降低产品的总拥有成本.从SQL ...
- codevs4189字典
沙茶 题目大意:求某一个字符串前缀有没有在n个字符串前缀里出现过 题解:Trie树 查询前缀有没有出现 代码: //codevs4189 #include<iostream> #inclu ...
- 从jvm角度来解析java语法糖
java有很多语法糖,比如自动拆箱,自动装箱,foreach等等,这些原理相信每一个入门教程里都有讲,但是我相信不是每一个人 都通过查看这些语法糖的字节码来确认这些原理,因为我也是现在才想看一下. 1 ...
- 微软系统工具包Sysinternals Suite官方下载地址
Sysinternals Suite是微软官方发布的系统工具包,其中包含数十款实用的绿色系统工具软件,个个身怀绝技,是你维护Windows系统不可或缺的好帮手. 最新版Sysinternals Sui ...