-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathP1110_.cpp
More file actions
39 lines (34 loc) · 719 Bytes
/
P1110_.cpp
File metadata and controls
39 lines (34 loc) · 719 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include <bits/stdc++.h>
using namespace std;
typedef struct node{
int l,r;
}node;
bool cmp(node a,node b){
return a.l<b.l;
}
int L,M;
node a[200];
signed main(){
while(cin>>L>>M){
for(int i=1;i<=M;i++){
cin>>a[i].l>>a[i].r;
}
sort(a+1,a+M+1,cmp);
for(int i=1;i<M;i++){
if(a[i].r>=a[i+1].l){
a[i+1].l = a[i].l;
a[i].l = -1;
if(a[i+1].r<=a[i].r)
a[i+1].r=a[i].r;
}
}
int t=0;
for(int i=1;i<=M;i++){
if(a[i].l!=-1){
t+=a[i].r-a[i].l+1;
}
}
cout<<L-t+1<<endl;
}
return 0;
}