CF1914C.Quests

普及-

通过率:0%

时间限制:2.50s

内存限制:256MB

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 \lt 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.

Monocarp 正在玩一款电脑游戏。为了提升角色等级,他可以完成任务。游戏中共有 nn 个任务,编号从 11 到 nn。

Monocarp 可以按照以下规则完成任务:

  • 第 11 个任务始终可被完成;
  • 第 ii 个任务可被完成,当且仅当所有编号 j<ij < i 的任务都至少已被完成过一次。

注意:Monocarp 可以多次完成同一个任务。

每次完成任务,角色会获得一定数量的经验值:

  • 第 ii 个任务首次完成时,获得 aia_i 点经验值;
  • 第 ii 个任务后续每次完成时,获得 bib_i 点经验值。

Monocarp 非常忙,因此他仅有时间完成至多 kk 个任务。你的任务是:计算 Monocarp 在最多完成 kk 个任务的前提下,所能获得的最大总经验值。

输入格式

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

The first line of each test case contains two integers nn and kk (1≤n≤2⋅1051 \le n \le 2 \cdot 10^5; 1≤k≤2⋅1051 \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 (1≤ai≤1031 \le a_i \le 10^3).

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

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

第一行包含一个整数 tt(1≤t≤1041 \le t \le 10^4)—— 表示测试用例的数量。

每个测试用例的第一行包含两个整数 nn 和 kk(1≤n≤2⋅1051 \le n \le 2 \cdot 10^5;1≤k≤2⋅1051 \le k \le 2 \cdot 10^5)—— 分别表示任务数量以及 Monocarp 最多能完成的任务数量。

第二行包含 nn 个整数 a1,a2,…,ana_1, a_2, \dots, a_n(1≤ai≤1031 \le a_i \le 10^3)。

第三行包含 nn 个整数 b1,b2,…,bnb_1, b_2, \dots, b_n(1≤bi≤1031 \le b_i \le 10^3)。

输入的额外约束:所有测试用例的 nn 值之和不超过 2⋅1052 \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.

对于每个测试用例,输出一个整数——即 Monocarp 最多完成 kk 个任务时所能获得的最大总经验值。

输入输出样例

  • 输入#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.

在第一个测试用例中,一种可能的任务完成序列为:1,1,2,3,2,4,41, 1, 2, 3, 2, 4, 4;其总经验值为 4‾+1+3‾+1‾+1+2‾+1=13\underline{4} + 1 + \underline{3} + \underline{1} + 1 + \underline{2} + 1 = 13(下划线标出的数字对应首次完成该任务时所获得的经验值)。

在第二个测试用例中,一种可能的任务完成序列为:1,11, 1;其总经验值为 1‾+3=4\underline{1} + 3 = 4。

在第三个测试用例中,一种可能的任务完成序列为:1,2,2,2,31, 2, 2, 2, 3;其总经验值为 3‾+2‾+3+3+4‾=15\underline{3} + \underline{2} + 3 + 3 + \underline{4} = 15。

输入解题思路,AI测评打分。不知道怎么写?

首页