-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsamu.cpp
More file actions
43 lines (42 loc) · 665 Bytes
/
samu.cpp
File metadata and controls
43 lines (42 loc) · 665 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
43
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
int t,n;
cin>>t;
while(t--)
{
cin>>n;
int arr[n+3];
for(int i=0;i<n;i++)
cin>>arr[i];
sort(arr,arr+n);
int _max=-1,temp=0;
while(1){
temp=0;
//cout<<endl;
//for(int i=0;i<n;i++)
// cout<<arr[i]<<" ";
//cout<<endl;
for(int j=1;j<n;j++){
//cout<<"i "<<arr[j]<<" "<<arr[j-1]<<endl;
temp+=(j+1)*abs(arr[j]-arr[j-1]);
}
//cout<<"temp "<<temp<<endl;
_max=max(_max,temp);
if(_max==temp)
{
for(int i=0;i<n;i++)
cout<<arr[i]<<" ";
cout<<endl;
cout<<"temp "<<temp<<endl;
}
int b=next_permutation(arr,arr+n);
if(b==0)
break;
}
cout<<_max<<endl;
}
return 0;
}