405549: GYM101991 I Ice-cream Knapsack

Memory Limit:1024 MB Time Limit:5 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

I. Ice-cream Knapsacktime limit per test5 secondsmemory limit per test1024 megabytesinputicecream.inoutputstandard output

There is a wonderful ice-cream shop that contains $$$N$$$ ice-creams, such that each ice-cream is represented by two numbers $$$C_i$$$ and $$$H_i$$$ denoting the number of calories and the happiness value, respectively.

You want to buy exactly $$$K$$$ ice-creams such that the calories of the densest ice-cream (the one with most calories) are as minimal as possible. If there is more than one way to do that, you want to maximize the total happiness of the ice-creams you will buy, that is the sum of the happiness values of the chosen ice-creams.

Input

The first line of the input contains a single integer $$$T$$$ specifying the number of test cases.

Each test case begins with a line containing two integers $$$N$$$ and $$$K$$$ ($$$1 \le K \le N \le 10^5$$$), in which $$$N$$$ is the number of ice-creams in the shop, and $$$K$$$ is the number of ice-creams you want to buy.

Then a line follows containing $$$N$$$ integers $$$C_1, \cdots, C_N$$$ ($$$0 \le C_i \le 10^9$$$), in which $$$C_i$$$ is the number of calories in the $$$i^{th}$$$ ice-cream. Then a line follows containing $$$N$$$ integers $$$H_1, \cdots, H_N$$$ ($$$0 \le H_i \le 10^9$$$), in which $$$H_i$$$ is the happiness value of the $$$i^{th}$$$ ice-cream.

Output

For each test case, print a single line containing two space-separated integers representing the calories of the densest ice-cream you will buy and the total happiness of the ice-creams you will buy, respectively.

Remember that your goal is to buy $$$K$$$ ice-creams such that the calories of the densest ice-cream (the one with most calories) are as minimal as possible. If there is more than one way to do that, you want to maximize the total happiness of the ice-creams you will buy.

ExampleInput
1
5 3
1 2 3 4 5
5 4 3 2 1
Output
3 12

加入题单

上一题 下一题 算法标签: