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

문제

Sogang agent is participating in “Squid Game: Two Bridges”. There are two parallel bridges, A and B, each consisting of $N$ steps. Each step has a score. The player starts at the beginning and moves to the end for $N$ rounds. The player can only move forward along the bridge.

In each round, the player can either:

  1. jump to the next step on the same bridge without using any energy, or
  2. spend one unit of energy to jump to the next step on the other bridge.

When the player lands on a step, the step’s score is added to the total. Unlike the original Squid Game, there is no danger of dying in this version, and the agent will always finish the game.

Specifically, the agent starts on the starting point of the left bridge (A) with an initial score of $0$ and initial energy $K$, shown in the figure below.

Given the score sequences $A$ (for the left bridge) and $B$ (for the right bridge), and the initial energy $K$, determine the maximum score the Sogang agent can achieve. The agent does not have to use all of the energy—it is also possible to use none at all.

입력

The first line contains two integers $N$ and $K$, the number of turns and the agent’s initial energy. $(1 \leq N \leq 100\,000, 0 \leq K \leq 4)$

The second lines contains $N$ integers, representing the left bridge's score sequence $A$. $(-1\,000 \leq A_i \leq 1\,000)$

The third line contains $N$ integers, representing the right birdge's sequence $B$. $(-1\,000 \leq B_i \leq 1\,000)$

출력

Print a single integer: the maximum score the Sogang agent can achieve.

서브태스크

번호배점제한
140

$1 \leq N \leq 1\,000, K = 2$

In this subtask, all $A_i$ are equal to 0.

220

$1 \leq N \leq 100\,000, K = 2$

In this subtask, all $A_i$ are equal to 0.

320

$1 \leq N \leq 100\,000, 0 \leq K \leq 2$

420

$1 \leq N \leq 100\,000, 0 \leq K \leq 4$

예제 입력 1

6 2
0 0 0 0 0 0
3 -9 5 -2 8 -5

예제 출력 1

11

This example satisfies the conditions of Subtask 1, 2, 3 and 4.

예제 입력 2

6 2
0 0 0 0 0 0
-1 -2 -1 -2 -1 -2

예제 출력 2

0

This example satisfies the conditions of Subtask 1, 2, 3 and 4.

예제 입력 3

6 2
3 3 3 2 1 7
1 2 1 7 7 2

예제 출력 3

30

This example satisfies the conditions of Subtask 3 and 4.

예제 입력 4

6 4
1 9 0 6 6 6
9 1 9 1 7 3

예제 출력 4

45

This example satisfies the conditions of Subtask 4.

예제 입력 5

1 0
-5
5

예제 출력 5

-5

This example satisfies the conditions of Subtask 3 and 4.

채점 및 기타 정보

  • 예제는 채점하지 않는다.