Problem H: Home Walk

Xem dạng PDF

Gửi bài giải

Điểm: 1,00
Giới hạn thời gian: 2.0s
Giới hạn bộ nhớ: 256M
Input: stdin
Output: stdout

Tác giả:
Dạng bài

Trong trường hợp đề bài hiển thị không chính xác, bạn có thể tải đề bài tại đây: Đề bài

The stilt game (a type of two-legged crutches) has a race track consisting of two parallel strips of cells (as shown below), each strip containing ~n~ + 2 cells, numbered from 0 (on the left) to ~n~ + 1 (on the right).

Cells from 1 to ~n~ in each strip have an integer written on them. Each player participating in the game uses stilts, starting from cell 0, and continuously moves forward by alternating between two legs, stepping into certain cells, and ending at cell ~n~ + 1. The movement follows these rules:

The left leg must always step into cells on the first strip, and the right leg must step into cells on the second strip.

If one leg has just stepped into cell ~i~ ~(i = 0, 1, . . . , n)~, then on the next step, the other leg can only step into cell ~j~ such that ~i + 1 ≤ j ≤ i + p~, where ~p~ is ~a~ given positive integer no greater than ~n~ (of course, it must also be true that ~j ≤ n + 1;~ ~p~ is referred to as the maximum jump length). The player's game ends when they step into cell ~n~ + 1, which is the last cell on the track. The score that the player receives after the game is the absolute value of the sum of all the numbers from the cells that the player steps on.

Determine the maximum score a player can achieve.


Input

The first line contains two integers ~n~ and ~p~ ~(1 ≤ n ≤ 10^6, 1 ≤ p ≤ n, 1 ≤ p ≤ 50)~.

The second line contains ~n~ integers, which are the numbers written on the cells from the left of the first strip.

The third line contains ~n~ integers, which are the numbers written on the cells from the left of the second strip.

All numbers have an absolute value not exceeding 32,000.


Output

A single value is the answer to the problem.


Sample Input 1

7 3
0 7 7 -4 5 9 2
1 6 2 -2 -2 2 -1

Sample Ouput 1

20

Note

The optimal cells to go to are cells (1, 1), (2, 2), (1, 3),(2, 5), (1, 6).


Bình luận

Hãy đọc nội quy trước khi bình luận.


Không có bình luận tại thời điểm này.