#include<bits/stdc++.h>
using namespace std;
#define int long long
#define pii pair<int,int>
#define all(x) x.begin(),x.end()
#define pb emplace_back
#define N 100010
#define ff first
#define ss second
pii a[N];
int n,m,ans,c[N];
bool f(int x){
int i,j,mx=0;
priority_queue<int,vector<int>,greater<int>>pq;
for(i=m-x,j=0;i<m;i++){
while(j<n&&a[j].ff<=c[i]) pq.push(a[j++].ss);
while(!pq.empty()&&pq.top()<mx) pq.pop();
if(pq.empty()) return 0;
mx=pq.top(),pq.pop();
}
return 1;
}
signed main(){
ios::sync_with_stdio(0);
cin.tie(0);
int i,j;
cin>>n>>m;
for(i=0;i<n;i++) cin>>a[i].ff>>a[i].ss;
for(i=0;i<m;i++)cin>>c[i];
sort(c,c+m);
sort(a,a+n);
for(i=m,j=0;i;i>>=1){
while(i+j<=m&&f(i+j))
ans=max(ans,i+j),j+=i;
}
cout<<ans<<'\n';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
304 KB |
Output is correct |
7 |
Correct |
0 ms |
332 KB |
Output is correct |
8 |
Correct |
1 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 |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
0 ms |
204 KB |
Output is correct |
14 |
Correct |
0 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
324 KB |
Output is correct |
16 |
Correct |
1 ms |
204 KB |
Output is correct |
17 |
Correct |
0 ms |
204 KB |
Output is correct |
18 |
Correct |
0 ms |
204 KB |
Output is correct |
19 |
Correct |
0 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
304 KB |
Output is correct |
7 |
Correct |
0 ms |
332 KB |
Output is correct |
8 |
Correct |
1 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 |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
0 ms |
204 KB |
Output is correct |
14 |
Correct |
0 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
324 KB |
Output is correct |
16 |
Correct |
1 ms |
204 KB |
Output is correct |
17 |
Correct |
0 ms |
204 KB |
Output is correct |
18 |
Correct |
0 ms |
204 KB |
Output is correct |
19 |
Correct |
0 ms |
204 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 |
364 KB |
Output is correct |
23 |
Correct |
1 ms |
332 KB |
Output is correct |
24 |
Correct |
1 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 |
332 KB |
Output is correct |
28 |
Correct |
1 ms |
332 KB |
Output is correct |
29 |
Correct |
1 ms |
328 KB |
Output is correct |
30 |
Correct |
1 ms |
332 KB |
Output is correct |
31 |
Correct |
2 ms |
332 KB |
Output is correct |
32 |
Correct |
1 ms |
332 KB |
Output is correct |
33 |
Correct |
0 ms |
324 KB |
Output is correct |
34 |
Correct |
1 ms |
332 KB |
Output is correct |
35 |
Correct |
1 ms |
332 KB |
Output is correct |
36 |
Correct |
2 ms |
328 KB |
Output is correct |
37 |
Correct |
2 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
304 KB |
Output is correct |
7 |
Correct |
0 ms |
332 KB |
Output is correct |
8 |
Correct |
1 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 |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
0 ms |
204 KB |
Output is correct |
14 |
Correct |
0 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
324 KB |
Output is correct |
16 |
Correct |
1 ms |
204 KB |
Output is correct |
17 |
Correct |
0 ms |
204 KB |
Output is correct |
18 |
Correct |
0 ms |
204 KB |
Output is correct |
19 |
Correct |
0 ms |
204 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 |
364 KB |
Output is correct |
23 |
Correct |
1 ms |
332 KB |
Output is correct |
24 |
Correct |
1 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 |
332 KB |
Output is correct |
28 |
Correct |
1 ms |
332 KB |
Output is correct |
29 |
Correct |
1 ms |
328 KB |
Output is correct |
30 |
Correct |
1 ms |
332 KB |
Output is correct |
31 |
Correct |
2 ms |
332 KB |
Output is correct |
32 |
Correct |
1 ms |
332 KB |
Output is correct |
33 |
Correct |
0 ms |
324 KB |
Output is correct |
34 |
Correct |
1 ms |
332 KB |
Output is correct |
35 |
Correct |
1 ms |
332 KB |
Output is correct |
36 |
Correct |
2 ms |
328 KB |
Output is correct |
37 |
Correct |
2 ms |
332 KB |
Output is correct |
38 |
Correct |
46 ms |
4992 KB |
Output is correct |
39 |
Correct |
45 ms |
5060 KB |
Output is correct |
40 |
Correct |
44 ms |
5232 KB |
Output is correct |
41 |
Correct |
56 ms |
5024 KB |
Output is correct |
42 |
Correct |
42 ms |
4980 KB |
Output is correct |
43 |
Correct |
43 ms |
5000 KB |
Output is correct |
44 |
Correct |
163 ms |
5964 KB |
Output is correct |
45 |
Correct |
57 ms |
5756 KB |
Output is correct |
46 |
Correct |
54 ms |
5720 KB |
Output is correct |
47 |
Correct |
64 ms |
5440 KB |
Output is correct |
48 |
Correct |
49 ms |
5532 KB |
Output is correct |
49 |
Correct |
272 ms |
5412 KB |
Output is correct |
50 |
Correct |
179 ms |
5416 KB |
Output is correct |
51 |
Correct |
42 ms |
5056 KB |
Output is correct |
52 |
Correct |
49 ms |
4992 KB |
Output is correct |
53 |
Correct |
47 ms |
5060 KB |
Output is correct |
54 |
Correct |
45 ms |
6212 KB |
Output is correct |
55 |
Correct |
75 ms |
5704 KB |
Output is correct |
56 |
Correct |
27 ms |
4464 KB |
Output is correct |
57 |
Correct |
16 ms |
2052 KB |
Output is correct |
58 |
Correct |
34 ms |
4872 KB |
Output is correct |
59 |
Correct |
31 ms |
4932 KB |
Output is correct |
60 |
Correct |
20 ms |
2000 KB |
Output is correct |
61 |
Correct |
123 ms |
3748 KB |
Output is correct |
62 |
Correct |
275 ms |
5992 KB |
Output is correct |
63 |
Correct |
290 ms |
5892 KB |
Output is correct |
64 |
Correct |
280 ms |
5880 KB |
Output is correct |
65 |
Correct |
286 ms |
5884 KB |
Output is correct |
66 |
Correct |
311 ms |
5856 KB |
Output is correct |
67 |
Correct |
242 ms |
5876 KB |
Output is correct |
68 |
Correct |
303 ms |
6008 KB |
Output is correct |
69 |
Correct |
295 ms |
5892 KB |
Output is correct |
70 |
Correct |
289 ms |
5996 KB |
Output is correct |
71 |
Correct |
257 ms |
5996 KB |
Output is correct |
72 |
Correct |
256 ms |
5868 KB |
Output is correct |
73 |
Correct |
258 ms |
6008 KB |
Output is correct |