首页 > 其他分享 >滑窗法--0与1状态转变

滑窗法--0与1状态转变

时间:2022-10-26 20:01:23浏览次数:50  
标签:Mishka -- theorems will int 窗法 转变 during minute


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

滑窗法--0与1状态转变_i++

 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 31 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.

#include<iostream>
#include<cstdio>
using namespace std;

const int Max_Num = 1e5 + 5;

int a[Max_Num];
int t[Max_Num];

int main() {
int n, k;
long long Sum = 0; int Sliding_Window = 0; int temp = 0;
scanf("%d%d", &n, &k);
for (int i = 0; i < n; i++) {
scanf("%d", a + i);
}
for (int i = 0; i < n; i++) {
scanf("%d", t + i);
}
for (int i = 0; i < n; i++) {
if (t[i]) {
Sum += a[i];
}
}
for (int i = 0; i < n; i++) {
if (!t[i]) {
temp += a[i];
}
if (i - k >= 0 && !t[i - k]) {
temp -= a[i - k];
}
Sliding_Window = temp > Sliding_Window ? temp : Sliding_Window;
}
Sum += Sliding_Window;
printf("%I64d\n", Sum);
return 0;
}

 

标签:Mishka,--,theorems,will,int,窗法,转变,during,minute
From: https://blog.51cto.com/u_13121994/5798308

相关文章

  • 尼姆博弈
    尼姆博弈:一种在博弈论中有基石作用的策略提醒:接下的分析有点烧脑描述:尼姆博弈是一个两人博弈,2名玩家轮流从数堆物品中拿取一定数量的物品,每次拿取时先选择某一堆,再从中......
  • MySQL 嵌套子查询 with子句 from子查询 in子查询 join组合
    一、适用场景和方法(1)适用场景考虑查询过程中是否存在以下情况:查询某些数据时需要分组才能得到,某些数据不需要分组就能得到或者分组条件不同;查询某些数据时需要where条......
  • 每天都可以见到的人,只有不了解才觉得正常
    罗素先生说得好:人人理应平等。实际上却远不是这样——特别是人与人有知识的差别。——王小波《长虫·草帽·细高挑》孤独恐怕就是,说的话别人迷迷糊糊,思考的问题别人......
  • 贪心--带最少的零钱
    题目描述你就要去购物了,现在你手上有N种不同面值的硬币,每种硬币有无限多个。为了方便购物,你希望带尽量少的硬币,但要能组合出1到X之间的任意值。输入格式第一行两个数X、N,以......
  • py第三方模块
    今日内容概要第三方模块的下载与使用网络爬虫模块之requests模块网络爬虫实战之爬取链家二手房数据自动化办公领域之openpyxl模块第三方模块的扩展(模块叠模块)......
  • 并查集--村村通
    题目描述某市调查城镇交通状况,得到现有城镇道路统计表。表中列出了每条道路直接连通的城镇。市政府“村村通工程”的目标是使全市任何两个城镇间都可以实现交通(但不一定有直......
  • 并查集--同时修路得到的最短时间
    题目背景AA地区在地震过后,连接所有村庄的公路都造成了损坏而无法通车。政府派人修复这些公路。题目描述给出A地区的村庄数NN,和公路数MM,公路是双向的。并告诉你每条公路的连......
  • 链表——两两交换链表中的节点
    #include<iostream>usingnamespacestd;structListNode{ intval; ListNode*next; ListNode(intval):val(val),next(NULL){};};//根据数组创建链表Lis......
  • 列表--list容器的使用(STL熟练掌握)
    题目描述一个学校里老师要将班上NN个同学排成一列,同学被编号为1\simN1∼N,他采取如下的方法:先将11号同学安排进队列,这时队列中只有他一个人;2-N2−N号同学依次入列,编号为i的......
  • .Net内置JSON序列化中文问题
    今天在用System.Text.Json序列化的时候遇到了中文序列化的一个问题,示例如下:JsonSerializer.Serialize(new{Name="你好"});预期结果是:{"Name":"你好"},但得到结果如下......