题解 | #两两配对差值最小#
两两配对差值最小
http://www.nowcoder.com/practice/60594521f1db4d75ad78266b0b35cfbb
#include <iostream> #include <cmath> #include <algorithm> using namespace std; const int N=1000035; int a[N]; int main() { int n;cin>>n; for(int i=0;i<n;i++) { cin>>a[i]; } sort(a,a+n); int i=0,j=n-1; int mn=-1;int res=0;int minnum=300; while(i<j) { if(a[i]+a[j]>mn) mn= a[i]+a[j]; if(a[i]+a[j]<minnum) minnum= a[i]+a[j]; res=mn-minnum; i++;j--; } cout<<res; return 0; }