CF1914C.Quests

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Monocarp is playing a computer game. In order to level up his character, he can complete quests. There are nn quests in the game, numbered from 11 to nn .

Monocarp can complete quests according to the following rules:

  • the 11 -st quest is always available for completion;
  • the ii -th quest is available for completion if all quests j<ij < i have been completed at least once.

Note that Monocarp can complete the same quest multiple times.

For each completion, the character gets some amount of experience points:

  • for the first completion of the ii -th quest, he gets aia_i experience points;
  • for each subsequent completion of the ii -th quest, he gets bib_i experience points.

Monocarp is a very busy person, so he has free time to complete no more than kk quests. Your task is to calculate the maximum possible total experience Monocarp can get if he can complete no more than kk quests.

输入格式

The first line contains a single integer tt ( 1t1041 \le t \le 10^4 ) — the number of test cases.

The first line of each test case contains two integers nn and kk ( 1n21051 \le n \le 2 \cdot 10^5 ; 1k21051 \le k \le 2 \cdot 10^5 ) — the number of quests and the maximum number of quests Monocarp can complete, respectively.

The second line contains nn integers a1,a2,,ana_1, a_2, \dots, a_n ( 1ai1031 \le a_i \le 10^3 ).

The third line contains nn integers b1,b2,,bnb_1, b_2, \dots, b_n ( 1bi1031 \le b_i \le 10^3 ).

Additional constraint on the input: the sum of nn over all test cases does not exceed 21052 \cdot 10^5 .

输出格式

For each test case, print a single integer — the maximum possible total experience Monocarp can get if he can complete no more than kk quests.

输入输出样例

  • 输入#1

    4
    4 7
    4 3 1 2
    1 1 1 1
    3 2
    1 2 5
    3 1 8
    5 5
    3 2 4 1 4
    2 3 1 4 7
    6 4
    1 4 5 4 5 10
    1 5 1 2 5 1

    输出#1

    13
    4
    15
    15

说明/提示

In the first test case, one of the possible quest completion sequences is as follows: 1,1,2,3,2,4,41, 1, 2, 3, 2, 4, 4 ; its total experience is equal to 4+1+3+1+1+2+1=13\underline{4} + 1 + \underline{3} + \underline{1} + 1 + \underline{2} + 1 = 13 (the underlined numbers correspond to the instances when we complete a quest for the first time).

In the second test case, one of the possible quest completion sequences is as follows: 1,11, 1 ; its total experience is equal to 1+3=4\underline{1} + 3 = 4 .

In the third test case, one of the possible quest completion sequences is as follows: 1,2,2,2,31, 2, 2, 2, 3 ; its total experience is equal to 3+2+3+3+4=15\underline{3} + \underline{2} + 3 + 3 + \underline{4} = 15 .

首页