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 ;
}

最新文章

  1. &quot;2013&quot;:爱你不容易
  2. HDU 1102 Constructing Roads (最小生成树)
  3. Centos环境下删除Oracle11g客户端文档
  4. Swift语法基础入门一(适合有C, OC开发人员)
  5. querySelectorAll 和 jQuery选择器
  6. Windows Azure 安全最佳实践 - 第 5 部分:基于Claim 的标识,单点登录
  7. HYSBZ 2243(树链剖分)
  8. 201521123088《JAVA程序设计》第8周学习总结
  9. box-shadow + animation 实现loading
  10. SAS9.2的增强编辑器注册解决方案
  11. 【面试】Spring事务面试考点吐血整理(建议珍藏)
  12. Vue项目中使用基于Vue.js的移动组件库cube-ui
  13. 利用clonezilla克隆、还原CentOS整个系统
  14. VMWare 虚拟机设置网络访问
  15. vivi.c框架
  16. linux2.6.30.4内核移植(3)&mdash;&mdash;yaffs文件系统移植
  17. iOS - 扩展UIButton的响应区域
  18. ethers.js-1
  19. 记录两道有趣的有关php数组的面试题
  20. What is Double Spending &amp; How Does Bitcoin Handle It?

热门文章

  1. ios上传图片遇见了一个TimeoutError(DOM Exception 23)异常
  2. LeetCode OJ:Add Binary(二进制相加)
  3. 【html】html笔记综合
  4. c# unicode 编码 中文转换 已测试(转)
  5. 绕过SQL限制的方法
  6. Switch能否使用String做参数
  7. 剑指offer-第六章面试中的各项能力(二叉树的深度)
  8. DbEntry 访问Access2010数据库
  9. Django-rest-framework多条件查询/分页/多表Json
  10. ajax()函数传值中文乱码解决方法介绍