PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#PS0000192. Tối đa số định lý ghi chép (Lecture Sleep)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Tối đa số định lý ghi chép (Lecture Sleep)

Lecture Sleep

Source: Codeforces

Version: Phuoc Hung OJ Extended

Problem Statement

A lecture lasts nn minutes. At minute ii the lecturer presents aia_i theorems. Mishka records all of them if ti=1t_i=1 (awake), and none if ti=0t_i=0 (asleep). You may use a technique exactly once to keep Mishka awake for exactly kk consecutive minutes starting at ll, where 1≤l≤n−k+11\le l\le n-k+1. Outside this interval the original behavior remains unchanged. Maximize the number of theorems recorded, without double counting.

Input

The first line contains n,kn,k. The second contains nn integers aia_i. The third contains nn integers tit_i.

Output

Print the maximum number of recorded theorems.

Subtasks

  • Subtask 1 (20 points): 1≤n≤5001\le n\le 500; 1≤ai≤1041\le a_i\le10^4; 0≤ti≤10\le t_i\le1; 1≤k≤n1\le k\le n.
  • Subtask 2 (30 points): 1≤n≤1000001\le n\le 100000; 1≤ai≤1041\le a_i\le10^4; 0≤ti≤10\le t_i\le1; 1≤k≤n1\le k\le n; k=nk=n.
  • Subtask 3 (50 points): 1≤n≤1000001\le n\le 100000; 1≤ai≤1041\le a_i\le10^4; 0≤ti≤10\le t_i\le1; 1≤k≤n1\le k\le n.

Example 1

Input

6 3
1 3 5 2 5 4
1 1 0 1 0 0

Output

16

Explanation

Initially 6 theorems are recorded. Choose minutes 3–5 for 10 extra, giving 16.

Example 2

Input

3 2
4 7 2
1 1 1

Output

13

Explanation

All minutes are already awake, so either window gives 13.