欢迎光临散文网 会员登陆 & 注册

算法竞赛2021 ICPC Southeastern Europe Regional Contest_Max Pair Matc

2022-03-31 16:09 作者:Clayton_Zhou  | 我要投稿


//#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;

}


算法竞赛2021 ICPC Southeastern Europe Regional Contest_Max Pair Matc的评论 (共 条)

分享到微博请遵守国家法律