#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
const int maxn=1000000+10;
int a[maxn];
struct Node{
int x;
int y;
int id;
}node[maxn];
bool cmp(Node a,Node b){
if(a.x!=b.x){
return a.x<=b.x;
}else{
return a.y<=b.y;
}
}
int main(){
int n,x,y;
scanf("%d",&n);
int num=0;
for(int i=0;i<2*n;i++){
scanf("%d%d",&x,&y);
node[i].x=x;
node[i].y=y;
}
sort(node,node+2*n,cmp);
for(int i=0;i<2*n;i++){
cout<<node[i].x<<" "<<node[i].y<<endl;
}
for(int i=0,j=0;i<2*n;i++,j=i){
while(node[i].y-node[j+1].y>0&&j<2*n){
// cout<<"d"<<node[i].y<<"f"<<node[j+1].x<<endl;
num+=node[j+1].y-node[j+1].x;
j++;
//cout<<i<<"a"<<num<<endl;
}
i=j;
if(node[i].y-node[i+1].x>0&&node[i].y<=node[i+1].y){
//cout<<"c"<<node[i].y<<node[i+1].x<<endl;
num+=node[i].y-node[i+1].x;
//cout<<i<<"b"<<num<<endl;
}
}
printf("%d\n",num);
return 0;
}
CCF201809-2 买菜(不知道哪里写错了)
最新推荐文章于 2022-03-19 18:55:03 发布