#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define pb push_back
#define int long long
#define fi first
#define se second
const int N = 3e5 + 5, M = 1e9 + 7, LG = 20;
int n , A[N] , q , s , v;
void solve(){
cin >> n >> q;
int mp[q+1] = {};
priority_queue<pair<int,int>> pq , st;
for (int i=1 ; i<=n ; i++){
cin >> s >> v;
pq.push({s,i});
st.push({v,i});
}
vector<int> f;
for (int i=1 ; i<=q ; i++){
cin >> s;
f.pb(s);
}
sort(f.rbegin() , f.rend());
int i = 0 , j = 0 , ans = 0 , pv = 0;
while(i < f.size() && pq.size()){
int u = f[i];
while(pq.size() && pq.top().fi > u){
mp[pq.top().se] = 1;
pq.pop();
}
if (!pq.size()) break;
while(st.size() && mp[st.top().se]){
st.pop();
}
if (!st.size()) break;
i++;
ans++;
mp[st.top().se] = 1;
st.pop();
}
cout << ans << endl;
}
signed main(){
// freopen("" , "r" , stdin);
// freopen("" , "w" , stdout);
// cout << setprecision(30);
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int ts = 1;
// cin >> ts;
while(ts--){
solve();
}
}
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |