本文为博主原创文章,未经允许不得转载。
我在csdn也同步发布了此文,链接 https://blog.csdn.net/umbrellalalalala/article/details/79891969
 
题目来源 http://codeforces.com/problemset/problem/961/B
【题目】

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
 
【分析】
我们根据样例输入来分析大意:我现在要去听一个6分钟的讲座,根据样例输入的第三行,我在第1、2、4分钟是醒着的,其他时间睡着了。其中有一种清醒手段能让我连续三分钟保持清醒(样例输入第一行第二个),例如在第1、2、3分钟使用这个手段,那么将改变我在第3分钟的状态(本来是0,代表睡着,现在由于使用了手段,于是醒了)。样例输入的第二行代表每分钟讲座会讲多少个数学定理,在醒着的时候我可以将定理全部记下来,然而在睡着的时候我无法记笔记。现在要求计算我最多能记多少笔记(在使用清醒手段的情况下)。
 
【示例代码】
 #include<stdio.h>
#include<stdlib.h>
#define MAX_N 100010
int a[MAX_N], t[MAX_N]; int main() {
int n, k, i;
long long sliding_window = , sum = , temp = ;
scanf("%d %d", &n, &k);
for (int i = ; i < n; i++) {
scanf("%d", a + i);
}
for (int i = ; i < n; i++) {
scanf("%d", t + i);
if (t[i] == )sum += a[i];
} for (int i = ; i < n; i++) {
if (!t[i])temp += a[i];
if (i - k >= && !t[i - k])temp -= a[i - k];
sliding_window = (temp > sliding_window) ? temp : sliding_window; }
printf("%I64d\n", sum + sliding_window);
system("pause");
return ;
}

codeforces——961B. Lecture Sleep的更多相关文章

  1. codeforces 499B.Lecture 解题报告

    题目链接:http://codeforces.com/problemset/problem/499/B 题目意思:给出两种语言下 m 个单词表(word1, word2)的一一对应,以及 profes ...

  2. [C2P3] Andrew Ng - Machine Learning

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

  3. [codeforces 519E]E. A and B and Lecture Rooms(树上倍增)

    题目:http://codeforces.com/problemset/problem/519/E 题意:给你一个n个点的树,有m个询问(x,y),对于每个询问回答树上有多少个点和x,y点的距离相等 ...

  4. codeforces 519E A and B and Lecture Rooms LCA倍增

    Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Submit Status Prac ...

  5. Codeforces Round #287 D.The Maths Lecture

    The Maths Lecture 题意:求存在后缀Si mod k =0,的n位数的数目.(n <=1000,k<=100); 用f[i][j]代表 长为i位,模k等于j的数的个数. 可 ...

  6. Codeforces 519E A and B and Lecture Rooms

    http://codeforces.com/contest/519/problem/E 题意: 给出一棵树和m次询问,每次询问给出两个点,求出到这两个点距离相等的点的个数. 思路: lca...然后直 ...

  7. codeforces 519E A and B and Lecture Rooms(LCA,倍增)

    转载请注明出处: http://www.cnblogs.com/fraud/          ——by fraud E. A and B and Lecture Rooms A and B are ...

  8. Codeforces Round #294 (Div. 2) A and B and Lecture Rooms(LCA 倍增)

    A and B and Lecture Rooms time limit per test 2 seconds memory limit per test 256 megabytes input st ...

  9. Codeforces Round #287 (Div. 2) D. The Maths Lecture [数位dp]

    传送门 D. The Maths Lecture time limit per test 1 second memory limit per test 256 megabytes input stan ...

随机推荐

  1. python类:类方法和静态方法

    http://blog.csdn.net/pipisorry/article/details/49516185 面相对象程序设计中,类方法和静态方法是经常用到的两个术语.逻辑上讲:类方法是只能由类名调 ...

  2. 我眼中的Linux设备树(一 概述)

    一 概述设备树(Device tree)是一套用来描述硬件属相的规则.ARM Linux采用设备树机制源于2011年3月份Linux创始人Linus Torvalds发的一封邮件,在这封邮件中他提倡A ...

  3. jquery easyui datagrid 分页实现---善良公社项目

    接着上篇文章,接下来给大家分享分页的实现,分页其实多多少少见过很有几种,框架中带的图片都特别的好看,会给用户以好的使用效果,具体实现,需要自己来补充代码: 图示1: 通常情况下页面数据的分页显示分成真 ...

  4. foreach 内嵌的使用

    foreach内部处理数据流的每条记录,进行关系操作,最后用generate返回数据给外部.但注意关系操作符不能作用于表达式,要将表达式提取成关系. foreach内部只支持distinct, fil ...

  5. ZooKeeper实现分布式锁

    使用场景          一般的锁是指单进程多线程的锁,在多线程并发编程中,用于线程之间的数据同步,保证共享资源的访问.而分布式锁,指的是在分布式环境下,保证跨进程.跨主机.跨网络的共享资源,实现互 ...

  6. (三十二)DatePicker和自定义键盘

    DatePicker通过设置Locale属性可以设置语言(注意手机语言也会影响到它的显示). 如果通过代码创建DatePicker,又要设置属性,使用下面的代码,注意locale是个枚举,初始化要填写 ...

  7. OpenCV 轮廓检测

    使用OpenCV可以对图像的轮廓进行检测.这是之前用过的代码,挺简单的,回顾一下.主要要进行以下2步操作: 1.cvThreshold():对图像进行二值化处理 2.cvFindContours(): ...

  8. Android中的Message机制

    对于Android的Message机制主要涉及到三个主要的类,分别是Handler.Message.Looper:首先对每个类做一个简单介绍:然后再介绍所谓的Android的Message机制是如何实 ...

  9. Cocos2d-swift V3.x 中的update方法

    在cocos2d V3.x中update方法如果实现,则会被自动调用;不用向早期的版本那样要显式schedule. 但是你还是要显式schedule其他方法或blocks使用node的schedule ...

  10. Linux - grep的一些进阶选项

    [root@www ~]# grep [-A] [-B] [--color=auto] '搜寻字串' filename 选项与参数: -A :后面可加数字,为 after 的意思,除了列出该行外,后续 ...