問題一覧 > 通常問題

No.3322 引っ張りだこ

レベル : / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (解説公開後に AC するまで非表示) / 解いたユーザー数 7
作問者 : ゆにたりー卿 / テスター : Rice_tawara459 hirayuu_yc DeltaStruct kazuppa elphe Andrew8128 のらら 👑 みうね 👑 seekworser
お気に入りにしたユーザー ProblemId : 11668 / 自分の提出
問題文最終更新日: 2025-11-01 00:33:26
In High Demand
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Show the original
第2回 岩井星人アンソロジープログラミングコンテスト Div.1 (順位表) の他の問題:

Problem Statement

Iwai Seijin, who has become quite popular, has been flooded with offers to appear on TV shows from both Earth and Planet Iwai. Truly in high demand, isn't it?

Let the present be day $0$. On each of days $1,\ \dots ,\ N$, Iwai Seijin appears on a TV show of either Earth or Planet Iwai, exactly one of the two.
To appear on a show of a planet, Iwai Seijin must be on that planet, and Iwai Seijin is on Earth on day $0$.

Here, for any $1 \leq i \leq N$, Iwai Seijin receives a fee of $A_i$ yen for appearing on the Earth show on day $i$, and a fee of $B_i$ yen for appearing on the Planet Iwai show on that day.

However, due to a shortage of spaceship fuel, moves from one planet to the other can be made at most $K$ times.

Note that for any $1 \leq i \leq N$, whichever planet Iwai Seijin was on during day $i - 1$, as long as $K$ moves have not yet been made, Iwai Seijin can appear on a show of the other planet on day $i$.

Find the maximum total fee, in yen, that Iwai Seijin can receive from day $1$ through day $N$.

You are given $T$ test cases; solve each of them.

Constraints

  • $1 \le T \le 10^5$
  • $1 \le N \le 2 \times 10^5$
  • $0 \le K \leq N$
  • $0 \le A_i,\ B_i \le 10^9$
  • The sum of $N$ over all test cases is at most $2 \times 10^5$
  • All input values are integers

Input

The input is given from standard input in the following format, where $\mathrm{case}_i$ denotes the $i$-th test case.

$T$
$\mathrm{case}_1$
$\mathrm{case}_2$
$\vdots$
$\mathrm{case}_T$

Each test case is given in the following format.

$N\ K$
$A_1\ \dots\ A_N$
$B_1\ \dots\ B_N$

Output

Output $T$ lines.
On the $i$-th line, output the maximum total fee that Iwai Seijin can receive from day $1$ through day $N$ for the $i$-th test case.

Sample

Sample 1
Input
2
6 2
3 1 4 1 5 9
2 7 1 8 2 8
1 0
0
1000000000
Output
33
0

For test case $1$, Iwai Seijin can receive $33$ yen by acting as follows. The maximum total fee that Iwai Seijin can receive from day $1$ through day $6$ is $33$ yen.

  1. Appear on the Earth show on day $1$, receiving a fee of $3$ yen.
  2. Move from Earth to Planet Iwai.
  3. Appear on the Planet Iwai shows on days $2,\ 3,\ 4$, receiving a fee of $7 + 1 + 8 = 16$ yen.
  4. Move from Planet Iwai to Earth. Since moves from one planet to the other have now been made $K = 2$ times, it is no longer possible to move to Planet Iwai after this.
  5. Appear on the Earth shows on days $5,\ 6$, receiving a fee of $5 + 9 = 14$ yen.

提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。