-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathleash.cpp
More file actions
46 lines (38 loc) · 855 Bytes
/
leash.cpp
File metadata and controls
46 lines (38 loc) · 855 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
40
41
42
43
44
45
46
#include <iostream>
#include <algorithm>
using namespace std;
bool cut[1000001];
struct input{
int start;
int end;
};
bool inputcomp(input a, input b){
return a.end<b.end;
}
int main(){
int n;
cin >> n;
input leash[n];
for(int i=0; i<n; i++){
cin >> leash[i].start >> leash[i].end;
leash[i].end+=leash[i].start;
}
sort(leash, leash+n, inputcomp);
// for(int i=0; i<n; i++){
// cout << leash[i].start << " " << leash[i].end << endl;
// }
int counter=0;
for(int i=0; i<n; i++){
if(!cut[i]){
cut[i]=true;
for(int j=0; j<n; j++){
if(leash[j].start < leash[i].end){
cut[j]=true;
}
}
counter++;
}
}
cout << counter << endl;
return 0;
}