for i in range(int(input())): N,P=[int(x) for x in input().split()] S=[int(y) for y in input().split()] S.sort() t=S[P-1] ans=0 for k in range(P-1): l=t-S[k] ans+=l print(ans)
3 4 3 3 1 9 100 6 2 5 5 1 2 3 4 5 5 7 7 1 7 7
14 1 6
The brand new service which powers Ideone!
Widget for compiling and running the source code in a web browser!