CF1430B.Barrels

普及/提高-

通过率:0%

AC君温馨提醒

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

题目描述

You have nn barrels lined up in a row, numbered from left to right from one. Initially, the ii -th barrel contains aia_i liters of water.

You can pour water from one barrel to another. In one act of pouring, you can choose two different barrels xx and yy (the xx -th barrel shouldn't be empty) and pour any possible amount of water from barrel xx to barrel yy (possibly, all water). You may assume that barrels have infinite capacity, so you can pour any amount of water in each of them.

Calculate the maximum possible difference between the maximum and the minimum amount of water in the barrels, if you can pour water at most kk times.

Some examples:

  • if you have four barrels, each containing 55 liters of water, and k=1k = 1 , you may pour 55 liters from the second barrel into the fourth, so the amounts of water in the barrels are [5,0,5,10][5, 0, 5, 10] , and the difference between the maximum and the minimum is 1010 ;
  • if all barrels are empty, you can't make any operation, so the difference between the maximum and the minimum amount is still 00 .

输入格式

The first line contains one integer tt ( 1t10001 \le t \le 1000 ) — the number of test cases.

The first line of each test case contains two integers nn and kk ( 1k<n21051 \le k < n \le 2 \cdot 10^5 ) — the number of barrels and the number of pourings you can make.

The second line contains nn integers a1,a2,,ana_1, a_2, \dots, a_n ( 0ai1090 \le a_i \le 10^{9} ), where aia_i is the initial amount of water the ii -th barrel has.

It's guaranteed that the total sum of nn over test cases doesn't exceed 21052 \cdot 10^5 .

输出格式

For each test case, print the maximum possible difference between the maximum and the minimum amount of water in the barrels, if you can pour water at most kk times.

输入输出样例

  • 输入#1

    2
    4 1
    5 5 5 5
    3 2
    0 0 0

    输出#1

    10
    0
首页