This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |