-
Notifications
You must be signed in to change notification settings - Fork 45
Expand file tree
/
Copy pathSam01.cpp
More file actions
40 lines (34 loc) · 768 Bytes
/
Sam01.cpp
File metadata and controls
40 lines (34 loc) · 768 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
#include<iostream>
#include<cstdio>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
int t;
cin>>t;
while(t--){
int n=1;
int i, j;
vector<int> a;
int data, size;
int sum=0;
cin>>size;
while(size--){
scanf("%d", &data);
a.push_back(data);
}
sort(a.begin(), a.end());
while(n<a.size()){
for(i=0; i<a.size(); ++i){
for(j=i+n; j<a.size(); ++j){
//cout<<"("<<i<<","<<j<<")"<<"->"<<a[j]-a[i]<<"\t";
sum += (a[j] - a[i]);
}
//cout<<endl;
}
n++;
}
cout<<sum<<endl;
}
return 0;
}