Squid Game: Two Bridges

면접 대비

시간 제한1초메모리 제한1024 MB

요약
길이가 N인 두 다리 A와 B가 있고 다리를 바꿀 때마다 에너지 K를 1씩 쓰며, 각 칸의 점수를 더해 얻을 수 있는 최대 총점을 구한다.
난이도

보통10점 중 6점

유형
동적 계획법, 배열, 그리디, 구현
정답자
아직 제출이 없습니다

문제

Sogang agent is participating in “Squid Game: Two Bridges”. There are two parallel bridges, A and B, each consisting of NN steps. Each step has a score. The player starts at the beginning and moves to the end for NN 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 00 and initial energy KK, shown in the figure below.

Given the score sequences AA (for the left bridge) and BB (for the right bridge), and the initial energy KK, 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 NN and KK, the number of turns and the agent’s initial energy. (1≤N≤100,000,0≤K≤4)(1 \leq N \leq 100\\,000, 0 \leq K \leq 4)

The second lines contains NN integers, representing the left bridge's score sequence AA. (−1,000≤A_i≤1,000)(-1\\,000 \leq A\_i \leq 1\\,000)

The third line contains NN integers, representing the right birdge's sequence BB. (−1,000≤B_i≤1,000)(-1\\,000 \leq B\_i \leq 1\\,000)

출력

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

예제5

  1. 예제 1

    입력
    6 2
    0 0 0 0 0 0
    3 -9 5 -2 8 -5
    
    예상 출력
    11
    
  2. 예제 2

    입력
    6 2
    0 0 0 0 0 0
    -1 -2 -1 -2 -1 -2
    
    예상 출력
    0
    
  3. 예제 3

    입력
    6 2
    3 3 3 2 1 7
    1 2 1 7 7 2
    
    예상 출력
    30
    
  4. 예제 4

    입력
    6 4
    1 9 0 6 6 6
    9 1 9 1 7 3
    
    예상 출력
    45
    
  5. 예제 5

    입력
    1 0
    -5
    5
    
    예상 출력
    -5