#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define f first
#define s second
#define ii pair <int,int>
#define pii pair <ll,ll>
const int N = 1e5;
const int MOD = 1e9 + 7;
const ll oo = 1e18;
ii a[N + 5];
int c[N + 5],n,m;
bool ok(int x)
{
priority_queue <int, vector <int>, greater <int>> pq;
int j = 1, tmp = 0;
for (int i = x; i <= m; ++i) {
while (j <= n && c[i] >= a[j].f) {
if (a[j].s >= tmp) pq.push(a[j].s);
++j;
}
if (pq.empty()) return false;
tmp = pq.top();
pq.pop();
}
return true;
}
int main()
{
ios_base::sync_with_stdio(0); cin.tie(0);
cin >> n >> m;
for (int i = 1; i <= n; ++i) {
cin >> a[i].f >> a[i].s;
}
for (int i = 1; i <= m; ++i) cin >> c[i];
sort(a + 1, a + 1 + n);
sort(c + 1, c + 1 + m);
int l = 1, r = m, save = 0;
while (l <= r) {
int mid = (l + r) >> 1;
if (ok(mid)) {
save = m - mid + 1;
r = mid - 1;
}
else l = mid + 1;
}
cout << save << '\n';
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
0 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
0 ms |
204 KB |
Output is correct |
11 |
Correct |
0 ms |
204 KB |
Output is correct |
12 |
Correct |
0 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
204 KB |
Output is correct |
14 |
Correct |
0 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
204 KB |
Output is correct |
16 |
Correct |
0 ms |
204 KB |
Output is correct |
17 |
Correct |
0 ms |
204 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
0 ms |
272 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
0 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
0 ms |
204 KB |
Output is correct |
11 |
Correct |
0 ms |
204 KB |
Output is correct |
12 |
Correct |
0 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
204 KB |
Output is correct |
14 |
Correct |
0 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
204 KB |
Output is correct |
16 |
Correct |
0 ms |
204 KB |
Output is correct |
17 |
Correct |
0 ms |
204 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
0 ms |
272 KB |
Output is correct |
20 |
Correct |
1 ms |
332 KB |
Output is correct |
21 |
Correct |
1 ms |
332 KB |
Output is correct |
22 |
Correct |
1 ms |
204 KB |
Output is correct |
23 |
Correct |
1 ms |
204 KB |
Output is correct |
24 |
Correct |
2 ms |
332 KB |
Output is correct |
25 |
Correct |
1 ms |
332 KB |
Output is correct |
26 |
Correct |
1 ms |
332 KB |
Output is correct |
27 |
Correct |
1 ms |
204 KB |
Output is correct |
28 |
Correct |
1 ms |
332 KB |
Output is correct |
29 |
Correct |
2 ms |
332 KB |
Output is correct |
30 |
Correct |
1 ms |
332 KB |
Output is correct |
31 |
Correct |
1 ms |
332 KB |
Output is correct |
32 |
Correct |
1 ms |
204 KB |
Output is correct |
33 |
Correct |
1 ms |
384 KB |
Output is correct |
34 |
Correct |
1 ms |
332 KB |
Output is correct |
35 |
Correct |
1 ms |
204 KB |
Output is correct |
36 |
Correct |
1 ms |
332 KB |
Output is correct |
37 |
Correct |
2 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
0 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
0 ms |
204 KB |
Output is correct |
11 |
Correct |
0 ms |
204 KB |
Output is correct |
12 |
Correct |
0 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
204 KB |
Output is correct |
14 |
Correct |
0 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
204 KB |
Output is correct |
16 |
Correct |
0 ms |
204 KB |
Output is correct |
17 |
Correct |
0 ms |
204 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
0 ms |
272 KB |
Output is correct |
20 |
Correct |
1 ms |
332 KB |
Output is correct |
21 |
Correct |
1 ms |
332 KB |
Output is correct |
22 |
Correct |
1 ms |
204 KB |
Output is correct |
23 |
Correct |
1 ms |
204 KB |
Output is correct |
24 |
Correct |
2 ms |
332 KB |
Output is correct |
25 |
Correct |
1 ms |
332 KB |
Output is correct |
26 |
Correct |
1 ms |
332 KB |
Output is correct |
27 |
Correct |
1 ms |
204 KB |
Output is correct |
28 |
Correct |
1 ms |
332 KB |
Output is correct |
29 |
Correct |
2 ms |
332 KB |
Output is correct |
30 |
Correct |
1 ms |
332 KB |
Output is correct |
31 |
Correct |
1 ms |
332 KB |
Output is correct |
32 |
Correct |
1 ms |
204 KB |
Output is correct |
33 |
Correct |
1 ms |
384 KB |
Output is correct |
34 |
Correct |
1 ms |
332 KB |
Output is correct |
35 |
Correct |
1 ms |
204 KB |
Output is correct |
36 |
Correct |
1 ms |
332 KB |
Output is correct |
37 |
Correct |
2 ms |
332 KB |
Output is correct |
38 |
Correct |
107 ms |
1860 KB |
Output is correct |
39 |
Correct |
90 ms |
1768 KB |
Output is correct |
40 |
Correct |
147 ms |
1860 KB |
Output is correct |
41 |
Correct |
133 ms |
1852 KB |
Output is correct |
42 |
Correct |
51 ms |
1440 KB |
Output is correct |
43 |
Correct |
43 ms |
1380 KB |
Output is correct |
44 |
Correct |
103 ms |
2204 KB |
Output is correct |
45 |
Correct |
229 ms |
4988 KB |
Output is correct |
46 |
Correct |
187 ms |
4968 KB |
Output is correct |
47 |
Correct |
173 ms |
4552 KB |
Output is correct |
48 |
Correct |
139 ms |
4484 KB |
Output is correct |
49 |
Correct |
163 ms |
3976 KB |
Output is correct |
50 |
Correct |
137 ms |
3984 KB |
Output is correct |
51 |
Correct |
47 ms |
4296 KB |
Output is correct |
52 |
Correct |
43 ms |
4384 KB |
Output is correct |
53 |
Correct |
55 ms |
4364 KB |
Output is correct |
54 |
Correct |
138 ms |
5308 KB |
Output is correct |
55 |
Correct |
73 ms |
4768 KB |
Output is correct |
56 |
Correct |
31 ms |
3340 KB |
Output is correct |
57 |
Correct |
21 ms |
1660 KB |
Output is correct |
58 |
Correct |
33 ms |
3828 KB |
Output is correct |
59 |
Correct |
46 ms |
3928 KB |
Output is correct |
60 |
Correct |
18 ms |
1580 KB |
Output is correct |
61 |
Correct |
83 ms |
2824 KB |
Output is correct |
62 |
Correct |
173 ms |
4776 KB |
Output is correct |
63 |
Correct |
168 ms |
4972 KB |
Output is correct |
64 |
Correct |
166 ms |
4812 KB |
Output is correct |
65 |
Correct |
173 ms |
4788 KB |
Output is correct |
66 |
Correct |
171 ms |
4772 KB |
Output is correct |
67 |
Correct |
161 ms |
4752 KB |
Output is correct |
68 |
Correct |
171 ms |
4768 KB |
Output is correct |
69 |
Correct |
165 ms |
4772 KB |
Output is correct |
70 |
Correct |
164 ms |
4756 KB |
Output is correct |
71 |
Correct |
157 ms |
4884 KB |
Output is correct |
72 |
Correct |
130 ms |
4776 KB |
Output is correct |
73 |
Correct |
143 ms |
4772 KB |
Output is correct |