961B Lecture Sleep

B. Lecture Sleep
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Your friend Mishka and you attend a calculus lecture. Lecture lasts n minutes. Lecturer tells aitheorems 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
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.




题意:有一个人很喜欢老师讲的微积分,但是再喜欢,也有时候要打瞌睡。输入n和k,n代表老师讲的n分钟,然后每分钟老师讲的公式。下面一行输入0和1对应上面的每分钟,如果为1,代表这个人听了老师课,并记下来了公式,如果为0,代表他睡着了,没有记下来公式。你有个技能,能够瞬间把他弄醒,让他继续听课,持续k分钟,,然后能记录下公式。让我们求出最大的记录公式数。

题解:先把所有能够听到的公式数求和,对没有听到的公式数进行前缀和  然后连续遍历k个数,求出最大值。就是你让他醒的时候能够听到的最大公式数。最后答案就是ans+maxn。

#include<bits/stdc++.h>
using namespace std;
const int N=1e5+10;
int a[N],b;
int main()
{
    int n,k,ans=0,maxn=0;
    cin>>n>>k;
    for(int i=1; i<=n; i++)
        cin>>a[i];
    for(int i=1; i<=n; i++)
    {
        cin>>b;
        if(b) ///先把所有这个上课能听的加起来
        {
            ans+=a[i];
            a[i]=0;      ///把已经加过的a[i]置为0
        }
        a[i]=a[i-1]+a[i];///打瞌睡的时候,没听到的,用前缀和保存
    }
    for(int i=k; i<=n; i++)///所有数中,遍历连续k个数字的最大和
        maxn=max(maxn,a[i]-a[i-k]);
    cout<<ans+maxn<<endl;
    return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

落凡尘.

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值