Pagini recente » Cod sursa (job #1441611) | Cod sursa (job #512410) | Cod sursa (job #1089225) | Cod sursa (job #1090528) | Cod sursa (job #1981984)
#include<fstream>
#include<algorithm>
using namespace std;
struct spec{
int x1,y1;
}A[100001];
int N,S,i,j,o;
bool cmp(spec x,spec y){
if(x.y1>y.y1)return false;
if(x.y1==y.y1 && x.x1>y.x1)return false;
return true;
}
int main()
{
freopen("heavymetal.in","r",stdin);
freopen("heavymetal.out","w",stdout);
scanf("%d",&N);
for(i=1;i<=N;++i)
scanf("%d%d",&A[i].x1,&A[i].y1);
sort(A+1,A+N+1,cmp);
o=1;
while(A[o].x1==A[o+1].x1 && o<N)++o;
S+=A[o].y1-A[o].x1;
for(i=o+1;i<=N;++i){
j=i;
while(A[j].x1==A[j+1].x1 && j<N)++j;
if(A[o].y1<=A[j].x1)
S+=A[j].y1-A[j].x1,o=j;
i=j;
}
printf("%d",S);
return 0;
}