贪心就完了,反正如果能够榨干一个数就榨干(指变为 0),然后全部给最大数加上那个数的值,
于是 $ans$ 为 $1-k+1$ 大数的和
#pragma GCC optimize("O3")
#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
#define debug(x) cerr << #x << ": " << x << endl
#define pb(a) push_back(a)
#define set0(a) memset(a,0,sizeof(a))
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define dwn(i,a,b) for(int i=(a);i>=(b);i--)
#define ceil(a,b) (a+(b-1))/b
#define INF 0x3f3f3f3f
#define ll_INF 0x7f7f7f7f7f7f7f7f
typedef long long ll;
typedef pair<int,int> PII;
typedef pair<double,double> PDD;
inline int read()
{
int x=0,y=1;char c=getchar();
while (c<'0'||c>'9') {if (c=='-') y=-1;c=getchar();}
while (c>='0'&&c<='9') x=x*10+c-'0',c=getchar();
return x*y;
}
const int N=2e5+5;
ll w[N];
int main(){
int T; cin>>T;
while(T--){
int n, k; cin>>n>>k;
rep(i,1,n) cin>>w[i];
sort(w+1, w+1+n);
dwn(i,n-1,n-k) w[n]+=w[i], w[i]=0;
sort(w+1, w+1+n);
cout<<w[n]-w[1]<<endl;
}
return 0;
}