B. Points and Minimum Distance(规律&数学)

Problem - 1895B - Codeforces

B. Points and Minimum Distance(规律&数学)_第1张图片

B. Points and Minimum Distance(规律&数学)_第2张图片

#include
using namespace std;
#define int long long
const int N=2e5+5;
int n,a[N]; 
void solve(){
	scanf("%lld",&n);
	for(int i=1;i<=n+n;i++){
		scanf("%lld",&a[i]);	
	}
	if(n==1){
		printf("0\n%lld%lld",a[1],a[2]);
		return;
	}
	sort(a+1,a+n+n+1);
	printf("%lld\n",a[n+n]-a[1]-a[n+1]+a[n]);
	for(int i=1;i<=n;i++){
		printf("%lld %lld\n",a[i],a[i+n]);
	}
}
signed main(){
	int t=1;
	scanf("%lld",&t);
	while(t--) solve();
	return 0;
}

你可能感兴趣的:(codeforces,算法,c语言,开发语言,c++,数据结构)