시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 1024 MB33232172.414%

문제

You are given two integer arrays $A$ and $B$, each of length $N$.

You want to select one contiguous subarray of length $K$ from each array to maximize the sum of the elements in the two chosen subarrays. However, the starting position of the subarray chosen from array $A$ must be strictly earlier than the starting position of the subarray from array $B$.

Formally, for integers $a$, $b$ satisfying $1 \le a < b \le N-K+1$ define

\[S(a, b) = \sum_{i = a}^{a + K - 1} A_i + \sum_{i = b}^{b + K - 1} B_i.\]

Your task is to find the maximum possible value of $S(a, b)$

입력

The first line contains two integers $N$ and $K$, the length of the arrays and the length of each subarray. ($2 \le N \le 100\,000, 1 \le K \le N-1$)

The second line contains $N$ integers $A_1, A_2, \ldots, A_N$. ($-1\,000 \le A_i \le 1\,000$)

The third line contains $N$ integers $B_1, B_2, \ldots, B_N$. ($-1\,000 \le B_i \le 1\,000$)

출력

Print a single integer: the maximum possible value of $S(a, b)$ under the given conditions.

서브태스크

번호배점제한
140

$2 \le N \le 100$

240

$2 \le N \le 3\,000$

320

$2 \le N \le 100\,000$

예제 입력 1

4 2
3 4 5 6
10 1 1 1

예제 출력 1

11

In the example above, choosing a and b as illustrated yields the optimal result, and the value of $S(a, b)$ is 4+5+1+1 = 11. This example satisfies the conditions of all subtasks.

예제 입력 2

2 1
1 2
3 4

예제 출력 2

5

This example satisfies the conditions of all subtasks.

예제 입력 3

6 3
1 1 10 10 10 1
-50 -50 -1 -1 -1 -50

예제 출력 3

18

This example satisfies the conditions of all subtasks.

채점 및 기타 정보

  • 예제는 채점하지 않는다.
  • 이 문제의 채점 우선 순위는 2이다.