961B.md (2318B)
1 Source: https://codeforces.com/problemset/problem/961/B 2 3 B. Lecture Sleep 4 5 time limit per test 6 7 1 second 8 9 memory limit per test 10 11 256 megabytes 12 13 input 14 15 standard input 16 17 output 18 19 standard output 20 21 Your friend Mishka and you attend a calculus lecture. Lecture lasts *n* minutes. Lecturer tells *a**i* theorems during the *i*-th minute. 22 23 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 *t**i* 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 — *a**i* during the *i*-th minute. Otherwise he writes nothing. 24 25 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. 26 27 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. 28 29 Input 30 31 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. 32 33 The second line of the input contains *n* integer numbers *a*1, *a*2, ... *a**n* (1 ≤ *a**i* ≤ 104) — the number of theorems lecturer tells during the *i*-th minute. 34 35 The third line of the input contains *n* integer numbers *t*1, *t*2, ... *t**n* (0 ≤ *t**i* ≤ 1) — type of Mishka's behavior at the *i*-th minute of the lecture. 36 37 Output 38 39 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. 40 41 Example 42 43 Input 44 45 ``` 46 6 3 47 1 3 5 2 5 4 48 1 1 0 1 0 0 49 ``` 50 51 Output 52 53 ``` 54 16 55 ``` 56 57 Note 58 59 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.