Movatterモバイル変換


[0]ホーム

URL:



Codeforces
In EnglishПо-русски
Enter |Register



Codeforces Round 995 (Div. 3)
Finished
→ Practice?
Want to solve the contest problems after the official contest ends? Just register for practice and you will be able to submit solutions.
→ Virtual participation
Virtual contest is a way to take part in past contest, as close as possible to participation on time. It is supported only ICPC mode for virtual contests.If you've seen these problems, a virtual contest is not for you - solve these problems in the archive.If you just want to solve some problem from a contest, a virtual contest is not for you - solve this problem in the archive.Never use someone else's code, read the tutorials or communicate with other person during a virtual contest.
→ Problem tags
binary search
brute force
data structures
greedy
sortings
*1600
No tag edit access
→ Contest materials
The problem statement has recently been changed.View the changes.
×
E. Best Price
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

A batch of Christmas trees has arrived at the largest store in Berland. $$$n$$$ customers have already come to the store, wanting to buy them.

Before the sales begin, the store needs to determine the price for one tree (the price is the same for all customers). To do this, the store has some information about each customer.

For the $$$i$$$-th customer, two integers $$$a_i$$$ and $$$b_i$$$ are known, which define their behavior:

  • if the price of the product is at most $$$a_i$$$, the customer will buy a tree and leave a positive review;
  • otherwise, if the price of the product is at most $$$b_i$$$, the customer will buy a tree but leave a negative review;
  • otherwise, the customer will not buy a tree at all.

Your task is to calculate the maximum possible earnings for the store, given that it can receive no more than $$$k$$$ negative reviews.

Input

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

The first line of each test case contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 2 \cdot 10^5$$$; $$$0 \le k \le n$$$).

The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 2 \cdot 10^9$$$).

The third line contains $$$n$$$ integers $$$b_1, b_2, \dots, b_n$$$ ($$$1 \le b_i \le 2 \cdot 10^9$$$; $$$a_i < b_i$$$).

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

Output

For each test case, print a single integer — the maximum possible earnings for the store, given that it can receive no more than $$$k$$$ negative reviews.

Example
Input
5
2 0
2 1
3 4
1 1
2
5
3 3
1 5 2
3 6 4
4 3
2 3 2 8
3 7 3 9
3 1
2 9 5
12 14 9
Output
2591415
Note

Consider the example from the statement:

  • In the first test case, the price should be set to $$$1$$$. Then both customers will buy one tree each and leave no negative reviews;
  • In the second test case, the price should be set to $$$5$$$. Then the only customer will buy a tree and leave a negative review;
  • In the third test case, the price should be set to $$$3$$$. Then all customers will buy one tree each, and the store will receive two negative reviews.
  • In the fourth test case, the price should be set to $$$7$$$. Then two customers will buy one tree each, and the store will receive one negative review.


Codeforces (c) Copyright 2010-2025 Mike Mirzayanov
The only programming contests Web 2.0 platform
Server time:May/12/2025 07:06:17 (n2).
Desktop version, switch tomobile version.
Privacy Policy |Terms and Conditions
Supported by
TON
 
ITMO University
 
 
 
 
User lists
 
 
Name

[8]ページ先頭

©2009-2025 Movatter.jp