Created
May 3, 2019 07:09
-
-
Save nickroh/4245f2cdad84c26a1cb6e83ac143c467 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <algorithm> | |
#include <string.h> | |
using namespace std; | |
int n; | |
long long sum=0; | |
struct _tuple{ | |
int x; | |
int y; | |
}; | |
_tuple arr[1000000]; | |
bool sf(_tuple a,_tuple b) | |
{ | |
if(a.y==b.y) | |
{ | |
return a.x<b.x; | |
} | |
return a.y<b.y; | |
} | |
void input() | |
{ | |
scanf("%d",&n); | |
for(int i=0;i<n;i++) | |
{ | |
scanf("%d %d",&arr[i].x,&arr[i].y); | |
} | |
} | |
void arrow() | |
{ | |
for(int i=0;i<n;i++) | |
{ | |
int tmp=0; | |
if(arr[i].y==arr[i+1].y && i<n-1) | |
{ | |
tmp=arr[i+1].x-arr[i].x; | |
} | |
if(arr[i].y==arr[i-1].y && i>0) | |
{ | |
if(tmp>arr[i].x-arr[i-1].x || tmp==0) | |
{ | |
tmp=arr[i].x-arr[i-1].x; | |
} | |
} | |
//printf("%d\n",tmp); | |
sum+=tmp; | |
} | |
} | |
void print() | |
{ | |
for(int i=0;i<n;i++) | |
{ | |
printf("%d %d\n",arr[i].x,arr[i].y); | |
} | |
} | |
int main() | |
{ | |
input(); | |
sort(arr,arr+n,sf); | |
// print(); | |
arrow(); | |
printf("%lld",sum); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment