#include <bits/stdc++.h>
#define mp make_pair
#define F first
#define S second
using namespace std;
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
int n, m;
cin >> n >> m;
pair<int, int> a[n];
int b[m];
for(int i=0; i< n; i++){
int x, y;
cin >> x >> y;
a[i]=mp(x, y);
}
for(int i=0; i< m; i++){
cin >> b[i];
}
sort(b, b+m);
sort(a, a+n);
int l=0;
int r=m;
while(l<=r){
int s=(l+r)/2;
int frst=m-s;
multiset<int> st;
int w=b[frst];
int ind=0;
for(int i=0; i< n; i++){
if(a[i].F<=w){
st.insert(a[i].S);
}
else {
ind=i;
break;
}
}
int cur;
if(st.empty()){
r=s-1;
continue;
}
else{
cur=*st.begin();
st.erase(st.find(cur));
}
bool ok =true;
for(int i=frst+1; i< m; i++){
w=b[i];
for(int j=ind; j<n; j++){
if(a[j].F<=w){
st.insert(a[j].S);
}
else{
ind=j;
break;
}
}
if(st.empty()){
ok=false;
continue;
}
else{
if(*st.rbegin()<cur){
ok=false;
continue;
}
else{
auto ptr=st.lower_bound(cur);
st.erase(ptr);
}
}
}
if(ok){
l=s+1;
}
else{
r=s-1;
}
}
cout << max(0,l-1) << '\n';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |