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>
#define IO_OP std::ios::sync_with_stdio(0); std::cin.tie(0);
#define F first
#define S second
#define V vector
#define PB push_back
#define MP make_pair
#define EB emplace_back
#define ALL(v) (v).begin(), (v).end()
#define debug(x) cerr << #x << " is " << x << endl
using namespace std;
typedef long long ll;
typedef pair<int, int> pi;
typedef V<int> vi;
const int INF = 1e9 + 7, N = 100005;
pi a[N];
int c[N];
int n, m;
bool ok(int mid) {
int lst = -1;
multiset<int> s;
for(int i = m - mid, j = 0; i < m; i++) {
while(j < n && a[j].F <= c[i]) {
s.insert(a[j].S);
j++;
}
auto it = s.lower_bound(lst);
if(it == s.end()) return false;
lst = *it;
s.erase(it);
}
return true;
}
signed main()
{
IO_OP;
cin >> n >> m;
for(int i=0;i<n;i++)
cin >> a[i].F >> a[i].S;
sort(a, a+n);
for(int i=0;i<m;i++)
cin >> c[i];
sort(c, c+m);
int l = 0, r = m;
while(l <= r) {
int mid = (l + r) / 2;
if(ok(mid)) l = mid + 1;
else r = mid - 1;
}
cout << r << endl;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |