Problem:
Please find the problem here.
Solution:
This is the easiest problem I ever had, just implement the given formulas! However, it does take me some time to write.
Please find the problem here.
Solution:
This is the easiest problem I ever had, just implement the given formulas! However, it does take me some time to write.
Code:
using namespace std;
int a[100],b[100];
main(){
int n;
cin>>n;
for(int i=0;i<2*n;i++){
cin>>a[i];
}
int maximum = 1000000;
for(int i=0;i<2*n;i++){
for(int j=i+1;j<2*n;j++){
for(int k=0;k<2*n;k++){
b[k]=a[k];
}
b[i]=b[j]= -1;
sort(b,b+2*n);
int ans=0;
for(int k=2;k<2*n-1;k+=2){
ans+= b[k+1]- b[k];
}
maximum=min(maximum,ans);
}
}
cout<<maximum;
}
No comments:
Post a Comment