Game

시간 제한2초메모리 제한2048 MB

요약
두 플레이어가 토큰을 오른쪽으로 옮기고 왼쪽으로 최대 c만큼 되돌리는 게임에서 첫 번째 플레이어가 모으는 꽃의 총 매력을 구한다.
난이도

어려움10점 중 8점

유형
동적 계획법, 게임 이론, 그리디
정답자
아직 제출이 없습니다

문제

Consider an infinite coordinate axis. Flowers bloom in points with coordinates 1,2,…,n1, 2, \ldots, n. The flower at point ii has attractiveness a_ia\_i.

Two players are playing a game. The first player starts at point 11. Then they proceed as follows:

  1. The first player, who now stands at point ii, picks an integer distance from ℓ_i\ell\_i to r_ir\_i, and moves to the right by this distance.
  2. If the first player's coordinate is more than nn, then the game stops.
  3. Otherwise, the second player moves the first player to the left by any distance from 00 to cc. However, this move can not end to the left of the point i+1i + 1.
  4. The first player takes the flower in his current point, and game returns to step 1.

The first player wants to maximize the total attractiveness of the flowers he takes, while the second player wants to minimize it.

Your task is to calculate the final total attractiveness of the flowers the first player has gathered if both players play optimally.

입력

The first line contains an integer tt (1≤t≤3⋅1051 \le t \le 3 \cdot 10^5), the number of test cases. The test cases follow.

The first line of each test case contains two integers: the number of flowers nn (1≤n≤3⋅1051 \le n \le 3 \cdot 10^5) and the limit cc (0≤c≤n0 \le c \le n). Each of the next three lines contains nn integers: these lines describe the arrays ℓ\ell, rr, and aa, in this order (1≤ℓ_i≤r_i≤n1 \le \ell\_i \le r\_i \le n; −109≤a_i≤109-10^9 \le a\_i \le 10^9). Note that attractiveness can be negative.

The sum of nn over all test cases does not exceed 3⋅1053 \cdot 10^5.

출력

For each test case, output a line with a single integer: the final total attractiveness if both players play optimally.

예제1

  1. 예제 1

    입력
    2
    6 2
    1 1 2 2 1 1
    2 1 3 2 1 1
    2 3 1 -1 -1 1
    4 4
    1 1 1 1
    2 2 1 1
    -1 -3 -2 -4
    
    예상 출력
    3
    -9