-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMAXDIFF.cpp
More file actions
42 lines (38 loc) · 811 Bytes
/
MAXDIFF.cpp
File metadata and controls
42 lines (38 loc) · 811 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include <iostream>
using namespace std;
int main(){
int t,n,k;
long long int wi;
cin>>t;
while(t!=0){
cin>>n>>k;
if(n-k<k){
k=n-k;
}
long long int arr[n]={0};
for(int i=0;i<n;i++){
cin>>wi;
arr[i]=wi;
}
for(int i=0;i<n;i++){
for(int j=0;j<n-1-i;j++){
int temp;
if(arr[j+1]<arr[j]){
temp=arr[j];
arr[j]=arr[j+1];
arr[j+1]=temp;
}
}
}
int sum1=0,sum2=0;
for(int i=0;i<k;i++){
sum1+=arr[i];
}
for(int i=k;i<n;i++){
sum2+=arr[i];
}
cout<<sum2-sum1<<endl;
t--;
}
return 0;
}