算法竞赛2021 ICPC Southeastern Europe Regional Contest_Max Pair Matc
//#include "stdafx.h"
#include<cstdio>
#include<cctype>
#include<vector>
#include<algorithm>
#include <queue>
using namespace std;
int n=2;
int num[200000][2]={0, 10,
7, 7,
9, 4,
2, 15 };
char vis[200000];
priority_queue<pair< int, int>> a;
int main(){
int tmp;
int x;
scanf("%d",&n);
for( x=0;x<2*n;x++)
{
scanf("%d",&num[x][0]);
scanf("%d",&num[x][1]);
}
for( x=0;x<2*n;x++)
if(num[x][0]>num[x][1])
{
tmp=num[x][0];
num[x][0]=num[x][1];
num[x][1]=tmp;
}
for( x=0;x<2*n;x++)
a.push(pair< int, int>(num[x][0]+num[x][1],x));
int K=n;
long long sum=0;
while (K)
{
vis[a.top().second]= 1;
//sum+=num[a.top().second][1];
a.pop();
K--;
}
for( x=0;x<2*n;x++)
{
if(vis[x])
sum+=num[x][1];
else
sum-=num[x][0];
}
printf("%lld\n",sum);
return 0;
}