#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pi pair<int, int>
#define pii pair<int, pi>
#define fi first
#define se second
int n, m;
pi A[200005];
int B[200005];
int32_t main(){
cin >> n >> m;
for(int i=1;i<=n;i++)cin >> A[i].fi >> A[i].se;
sort(A+1, A+n+1);
for(int i=1;i<=m;i++)cin >> B[i];
sort(B+1, B+m+1);
int lo = 1, hi = min(n, m), ans = lo - 1;
while(lo <= hi){
int mid = (lo + hi)>>1;
int in = 1;
priority_queue<int, vector<int>, greater<int> >pq;
int pre = 0;
bool f = 1;
for(int i=m-mid+1;i<=m;i++){
while(in <= n && A[in].fi <= B[i])pq.push(A[in].se), in++;
if(pq.empty())f = 0;
else{
while(!pq.empty() && pq.top() < pre)pq.pop();
if(pq.empty())f = 0;
else pre = pq.top(), pq.pop();
}
}
if(f)lo = mid + 1, ans= mid;
else hi = mid - 1;
}
cout << ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
308 KB |
Output is correct |
10 |
Correct |
0 ms |
304 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
304 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
308 KB |
Output is correct |
10 |
Correct |
0 ms |
304 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
304 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
2 ms |
340 KB |
Output is correct |
21 |
Correct |
2 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
2 ms |
324 KB |
Output is correct |
24 |
Correct |
3 ms |
340 KB |
Output is correct |
25 |
Correct |
2 ms |
352 KB |
Output is correct |
26 |
Correct |
3 ms |
340 KB |
Output is correct |
27 |
Correct |
2 ms |
340 KB |
Output is correct |
28 |
Correct |
2 ms |
340 KB |
Output is correct |
29 |
Correct |
3 ms |
360 KB |
Output is correct |
30 |
Correct |
2 ms |
340 KB |
Output is correct |
31 |
Correct |
2 ms |
316 KB |
Output is correct |
32 |
Correct |
1 ms |
340 KB |
Output is correct |
33 |
Correct |
1 ms |
316 KB |
Output is correct |
34 |
Correct |
2 ms |
324 KB |
Output is correct |
35 |
Correct |
1 ms |
316 KB |
Output is correct |
36 |
Correct |
3 ms |
340 KB |
Output is correct |
37 |
Correct |
2 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
308 KB |
Output is correct |
10 |
Correct |
0 ms |
304 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
304 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
2 ms |
340 KB |
Output is correct |
21 |
Correct |
2 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
2 ms |
324 KB |
Output is correct |
24 |
Correct |
3 ms |
340 KB |
Output is correct |
25 |
Correct |
2 ms |
352 KB |
Output is correct |
26 |
Correct |
3 ms |
340 KB |
Output is correct |
27 |
Correct |
2 ms |
340 KB |
Output is correct |
28 |
Correct |
2 ms |
340 KB |
Output is correct |
29 |
Correct |
3 ms |
360 KB |
Output is correct |
30 |
Correct |
2 ms |
340 KB |
Output is correct |
31 |
Correct |
2 ms |
316 KB |
Output is correct |
32 |
Correct |
1 ms |
340 KB |
Output is correct |
33 |
Correct |
1 ms |
316 KB |
Output is correct |
34 |
Correct |
2 ms |
324 KB |
Output is correct |
35 |
Correct |
1 ms |
316 KB |
Output is correct |
36 |
Correct |
3 ms |
340 KB |
Output is correct |
37 |
Correct |
2 ms |
340 KB |
Output is correct |
38 |
Correct |
181 ms |
6088 KB |
Output is correct |
39 |
Correct |
177 ms |
6172 KB |
Output is correct |
40 |
Correct |
219 ms |
6320 KB |
Output is correct |
41 |
Correct |
199 ms |
6196 KB |
Output is correct |
42 |
Correct |
124 ms |
5480 KB |
Output is correct |
43 |
Correct |
127 ms |
5468 KB |
Output is correct |
44 |
Correct |
231 ms |
6624 KB |
Output is correct |
45 |
Correct |
321 ms |
6680 KB |
Output is correct |
46 |
Correct |
258 ms |
6800 KB |
Output is correct |
47 |
Correct |
280 ms |
6084 KB |
Output is correct |
48 |
Correct |
233 ms |
6144 KB |
Output is correct |
49 |
Correct |
229 ms |
5416 KB |
Output is correct |
50 |
Correct |
218 ms |
5460 KB |
Output is correct |
51 |
Correct |
125 ms |
5452 KB |
Output is correct |
52 |
Correct |
118 ms |
5544 KB |
Output is correct |
53 |
Correct |
118 ms |
5380 KB |
Output is correct |
54 |
Correct |
226 ms |
7452 KB |
Output is correct |
55 |
Correct |
167 ms |
6128 KB |
Output is correct |
56 |
Correct |
91 ms |
4424 KB |
Output is correct |
57 |
Correct |
52 ms |
2048 KB |
Output is correct |
58 |
Correct |
83 ms |
5572 KB |
Output is correct |
59 |
Correct |
102 ms |
5620 KB |
Output is correct |
60 |
Correct |
43 ms |
2032 KB |
Output is correct |
61 |
Correct |
139 ms |
3700 KB |
Output is correct |
62 |
Correct |
295 ms |
6352 KB |
Output is correct |
63 |
Correct |
321 ms |
6536 KB |
Output is correct |
64 |
Correct |
300 ms |
6328 KB |
Output is correct |
65 |
Correct |
303 ms |
6376 KB |
Output is correct |
66 |
Correct |
293 ms |
6356 KB |
Output is correct |
67 |
Correct |
302 ms |
6348 KB |
Output is correct |
68 |
Correct |
293 ms |
6464 KB |
Output is correct |
69 |
Correct |
318 ms |
6348 KB |
Output is correct |
70 |
Correct |
295 ms |
6352 KB |
Output is correct |
71 |
Correct |
284 ms |
6364 KB |
Output is correct |
72 |
Correct |
271 ms |
6356 KB |
Output is correct |
73 |
Correct |
268 ms |
6380 KB |
Output is correct |