Your friend Mishka and you attend a calculus lecture. Lecture lasts n minutes. Lecturer tells ai theorems during the i-th minute.

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.

Input

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.

Output

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.

Example
Input

Copy
6 3
1 3 5 2 5 4
1 1 0 1 0 0
Output

Copy
16
Note

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(前缀和)的更多相关文章

  1. [C2P3] Andrew Ng - Machine Learning

    ##Advice for Applying Machine Learning Applying machine learning in practice is not always straightf ...

  2. Lecture Sleep(尺取+前缀和)

    Description 你的朋友Mishka和你参加一个微积分讲座.讲座持续n分钟.讲师在第i分钟讲述ai个定理.   米什卡真的对微积分很感兴趣,尽管在演讲的所有时间都很难保持清醒.给你一个米什卡行 ...

  3. Trie(前缀树/字典树)及其应用

    Trie,又经常叫前缀树,字典树等等.它有很多变种,如后缀树,Radix Tree/Trie,PATRICIA tree,以及bitwise版本的crit-bit tree.当然很多名字的意义其实有交 ...

  4. HDU1671——前缀树的一点感触

    题目http://acm.hdu.edu.cn/showproblem.php?pid=1671 题目本身不难,一棵前缀树OK,但是前两次提交都没有成功. 第一次Memory Limit Exceed ...

  5. 【手记】注意BinaryWriter写string的小坑——会在string前加上长度前缀length-prefixed

    之前以为BinaryWriter写string会严格按构造时指定的编码(不指定则是无BOM的UTF8)写入string的二进制,如下面的代码: //将字符串"a"写入流,再拿到流的 ...

  6. ASP.NET Core MVC 配置全局路由前缀

    前言 大家好,今天给大家介绍一个 ASP.NET Core MVC 的一个新特性,给全局路由添加统一前缀.严格说其实不算是新特性,不过是Core MVC特有的. 应用背景 不知道大家在做 Web Ap ...

  7. 如何处理CSS3属性前缀

    今天闲来无聊,重新来说说CSS3前缀的问题.在春节前和@一丝姐姐说起Sass中有关于gradient的mixins.姐姐说: 为什么还要用mixin呢?为什么不使用Autoprefixer?使用Aut ...

  8. context:component-scan" 的前缀 "context" 未绑定。

    SpElUtilTest.testSpELLiteralExpressiontestSpELLiteralExpression(cn.zr.spring.spel.SpElUtilTest)org.s ...

  9. 解决adobe air sdk打包 apk后自动在包名前面加上air. (有个点)前缀的问题

    早就找到了这个方法,但是一直忙没心思写博客. 默认情况下,所有 AIR Android 应用程序的包名称都带 air 前缀.若不想使用此默认行为,可将计算机环境变量 AIR_NOANDROIDFLAI ...

随机推荐

  1. jQueryValidation插件API 学习

    一般格式: $('').viladata({ rules:{ username:{ required:true, maxlength:2, minlength:10, remote:{ url:&qu ...

  2. react-webpack(二)

    const path = require('path'); const webpack = require('webpack'); const HtmlWebpackPlugin = require( ...

  3. New Concept English three (26)

    34w/m 54words No one can avoid being influenced by advertisements. Much as we may pride ourselves on ...

  4. 【网络】<网络是怎样连接的>笔记

    [一] 浏览器 http://user:pwd@hosturl:port/dir/of/file 基本思路: 1.1 生成http请求信息 包含“对什么”“进行怎样的操作”两个方法.一般常用操作是GE ...

  5. 【python】《利用python进行数据分析》笔记

    [第三章]ipython C-a 到行首 C-e 到行尾 %timeit 测量语句时间,%time是一次,%timeit是多次. %pdb是自动调试的开关. %debug中,可以用b 12在第12行设 ...

  6. Linux系统下的shutdown命令用于安全的关闭/重启计算机

    Linux系统下的shutdown命令用于安全的关闭/重启计算机,它不仅可以方便的实现定时关机,还可以由用户决定关机时的相关参数.在执行shutdown命令时,系统会给每个终端(用户)发送一条屏显,提 ...

  7. 如何在win7下装ubuntu雙系統

    如何在win7下装ubuntu(硬盘版安装) 1)首先还是分区,在计算机上右键--管理--磁盘管理 装Ubuntu分配的硬盘大小最好是(20G以上)不要太小,这里请注意,ubuntu和windows文 ...

  8. 开源项目Universal Image Loader for Android 说明文档 (1) 简介

     When developing applications for Android, one often facesthe problem of displaying some graphical ...

  9. windows 下多线程

    unsigned uiThread2ID; HANDLE handle = (HANDLE)_beginthreadex(NULL, , ThreadUploadFun, NULL, CREATE_S ...

  10. cowboy实现websocket

    使用cowboy实现websocket主要实现以下回调函数 下面的函数返回值要具体弄清楚原因参考 websocket具体协议  主要就是两个部分 握手和数据传输 -export([init/3]).  ...