fork download
  1. for i in range(int(input())):
  2. N,P=[int(x) for x in input().split()]
  3. S=[int(y) for y in input().split()]
  4. S.sort()
  5. t=S[P-1]
  6. ans=0
  7. for k in range(P-1):
  8. l=t-S[k]
  9. ans+=l
  10. print(ans)
  11.  
  12.  
Success #stdin #stdout 0.02s 9180KB
stdin
3
4 3
3 1 9 100
6 2
5 5 1 2 3 4
5 5
7 7 1 7 7
stdout
14
1
6