CF2096B.Wonderful Gloves

传统题 时间 2000 ms 内存 256 MiB 5 尝试 1 已通过 1 标签

Wonderful Gloves

You are the proud owner of many colorful gloves, and you keep them in a drawer. Each glove is in one of nn colors numbered 11 to nn. Specifically, for each ii from 11 to nn, you have lil_i left gloves and rir_i right gloves with color ii.

Unfortunately, it's late at night, so you can't see any of your gloves. In other words, you will only know the color and the type (left or right) of a glove after you take it out of the drawer.

A matching pair of gloves with color ii consists of exactly one left glove and one right glove with color ii. Find the minimum number of gloves you need to take out of the drawer to guarantee that you have at least kk matching pairs of gloves with different colors.

Formally, find the smallest positive integer xx such that:

  • For any set of xx gloves you take out of the drawer, there will always be at least kk matching pairs of gloves with different colors.

Input

Each test contains multiple test cases. The first line contains the number of test cases tt (1t1041 \le t \le 10^4). The description of the test cases follows.

The first line of each test case contains two integers nn, kk (1kn21051 \leq k \leq n \leq 2 \cdot 10^5) — the number of different colors, and the minimum number of required matching pairs of gloves.

The second line of each test case contains nn integers l1,l2,,lnl_1, l_2, \ldots, l_n (1li1091 \leq l_i \leq 10^9) — the number of left gloves with color ii for each ii from 11 to nn.

The third line of each test case contains nn integers r1,r2,,rnr_1, r_2, \ldots, r_n (1ri1091 \leq r_i \leq 10^9) — the number of right gloves with color ii for each ii from 11 to nn.

It is guaranteed that the sum of nn over all test cases does not exceed 21052 \cdot 10^5.

Output

For each test case, output a single integer — the minimum number of gloves you need to take out of the drawer.

Note

In the first test case, you must take out all of the gloves, so the answer is 66.

In the second test case, the answer is 101101. If you take out 100100 gloves or fewer, then it is possible that all of them are left gloves, which means you won't have a matching pair of gloves.

In the third test case, the answer is 303303. If you only take out 302302 gloves, then one possible scenario is as follows:

  • Color 11: 100100 left gloves, 200200 right gloves
  • Color 22: 11 left glove, 00 right gloves
  • Color 33: 00 left gloves, 11 right glove

You only have multiple matching pairs of gloves with color 11. So you won't have at least 22 matching pairs of gloves with different colors.

Samples

5
3 3
1 1 1
1 1 1
1 1
100
1
3 2
100 1 1
200 1 1
5 2
97 59 50 87 36
95 77 33 13 74
10 6
97 59 50 87 36 95 77 33 13 74
91 14 84 33 54 89 68 34 14 15
6
101
303
481
1010

在线编程 IDE

建议全屏模式获得最佳体验