-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlight.cpp
63 lines (58 loc) · 1.38 KB
/
light.cpp
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#include <algorithm>
#include <fstream>
#include <iostream>
#include <vector>
using namespace std;
typedef pair<int, int> pii;
ifstream input("light.inp");
ofstream output("light.out");
vector<pii> v;
int main() {
int count;
input >> count;
for (int i = 0; i < count; i++) {
int j, k;
input >> j >> k;
v.push_back({j, k});
}
sort(v.begin(), v.end());
int tc;
input >> tc;
for (int i = 0; i < tc; i++) {
int result = 0;
int ls, rs, mid;
int temp = 0;
input >> ls >> rs;
mid = ls;
for (int j = 0; j < v.size(); j++) {
int left = v[j].first;
int right = v[j].second;
if (left <= mid) {
if (right > temp) {
temp = right;
}
} else {
mid = temp;
result++;
if (mid >= rs) {
break;
}
if (left <= mid) {
if (right > temp) {
temp = right;
}
} else {
break;
}
}
if (j == v.size() - 1 && temp >= rs) {
result++;
}
}
if (temp >= rs) {
output << result << "\n";
} else {
output << "-1\n";
}
}
}