mirror of
https://github.com/Kiritow/OJ-Problems-Source.git
synced 2024-03-22 13:11:29 +08:00
Create 1064.cpp
This commit is contained in:
parent
4af6b41127
commit
305b08a8ae
21
QUSTOJ/1064.cpp
Normal file
21
QUSTOJ/1064.cpp
Normal file
|
@ -0,0 +1,21 @@
|
|||
#include <cstdio>
|
||||
#include <algorithm>
|
||||
using namespace std;
|
||||
const int N=20010;
|
||||
struct line{int l,r;}s[N];
|
||||
int n,head,tail;
|
||||
long long ans;
|
||||
bool cmp(line a,line b){return a.l==b.l? a.r<b.r:a.l<b.l;}
|
||||
int main(){
|
||||
//freopen("1165.in","r",stdin);freopen("1165.out","w",stdout);
|
||||
scanf("%d",&n);
|
||||
for(int i=1;i<=n;i++) scanf("%d%d",&s[i].l,&s[i].r);
|
||||
sort(s+1,s+n+1,cmp);
|
||||
for(int i=1;i<n;i++){
|
||||
if(s[i].r>=s[i+1].l) s[i+1].l=s[i].l,s[i+1].r=max(s[i].r,s[i+1].r);
|
||||
else ans+=s[i].r-s[i].l;
|
||||
}
|
||||
ans+=s[n].r-s[n].l;
|
||||
printf("%lld",ans);
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue
Block a user