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 f first
#define s second
int N, M;
vector<pair<int, int>> pictures;
vector<int> frames;
bool check(int x) {
int j = 1;
int prev = 0;
bool flag = true;
priority_queue<int, vector<int>, greater<int>> pq;
for (int i = M-x+1; i <= M; i++) {
while (j <= N && pictures[j].f <= frames[i]) {
pq.push(pictures[j].s);
j++;
}
if (pq.empty()) {
flag = false;
}
else {
while (!pq.empty() && (pq.top() < prev)) {
pq.pop();
}
if (pq.empty()) {
flag = false;
}
else {
prev = pq.top();
pq.pop();
}
}
}
return flag;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cin >> N >> M;
pictures.resize(N+1);
frames.resize(M+1);
for (int i = 1; i <= N; i++) {
cin >> pictures[i].f >> pictures[i].s;
}
for (int i = 1; i <= M; i++) {
cin >> frames[i];
}
sort(pictures.begin(), pictures.end());
sort(frames.begin(), frames.end());
int high = min(N, M);
int low = 1;
int ans = low-1;
while (low <= high) {
int mid = (low+high)/2;
if (check(mid)) {
ans = mid;
low = mid+1;
}
else {
high = mid-1;
}
}
cout << ans << "\n";
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |