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;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
#define all(x) x.begin(), x.end()
template <typename T1, typename T2> inline void chkmin(T1 &x, const T2 & y) {if (x > y) x = y;}
template <typename T1, typename T2> inline void chkmax(T1 &x, const T2 & y) {if (x < y) x = y;}
struct event{
int s, v;
event () {}
event(int _s, int _v) {
s = _s, v = _v;
}
};
bool operator<(const event & a, const event & b) {
return tie(a.v, a.s) < tie(b.v, b.s);
}
int n, m;
vector<event> a;
vector<int> c;
void read() {
cin >> n >> m;
a.resize(n);
for (auto &i : a) {
cin >> i.s >> i.v;
}
sort(all(a));
c.resize(m);
for (auto &i : c) {
cin >> i;
}
sort(all(c));
reverse(all(c));
}
struct segment_tree{
vector<int> tree;
int n;
segment_tree() {}
segment_tree(int sz) {
n = sz;
tree.assign(n, 0);
}
int get(int r) {
int ans = 0;
for (int i = 0; i <= r; i++)
chkmax(ans, tree[i]);
return ans;
}
void upd(int pos, int val) {
tree[pos] = val;
}
};
bool check(int cnt) {
vector<int> fc;
for (int i = 0; i < cnt; i++)
fc.push_back(c[i]);
reverse(all(fc));
/*cout << "fc = " << endl;
for (auto i : fc)
cout << i << " ";
cout << endl;*/
//segment_tree tree(n + m);
int mx = 0;
for (auto i : a) {
int have = mx;
int min_pos = lower_bound(all(fc), i.s) - fc.begin();
if (min_pos > have) continue;
//tree.upd(i.s, have + 1);
chkmax(mx, have + 1);
/*cout << "tree = " << endl;
for (auto i : tree.tree)
cout << i << " ";
cout << endl;*/
}
return mx >= cnt;//tree.get(n + m - 1) >= cnt;
}
int ans;
void build() {
vector<int> have;
for (auto i : a) {
have.push_back(i.s);
}
for (auto i : c) {
have.push_back(i);
}
sort(all(have));
have.resize(unique(all(have)) - have.begin());
for (auto &i : a) {
i.s = lower_bound(all(have), i.s) - have.begin();
}
for (auto &i : c) {
i = lower_bound(all(have), i) - have.begin();
}
}
void run() {
build();
/*cout << "a = " << endl;
for (auto i : a) {
cout << i.s << " " << i.v << endl;
}
cout << "c = " << endl;
for (auto i : c) {
cout << i << " ";
}
cout << endl;
cout << check(5) << endl;
exit(0);*/
int l = 0, r = min(n, m) + 1;
while (l < r - 1) {
int mid = (l + r) / 2;
if (check(mid))
l = mid;
else
r = mid;
}
ans = l;
}
void write() {
cout << ans << endl;
}
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
read();
run();
write();
return 0;
}
/*
6 6
1 2
1 1
2 2
2 2
2 1
1 2
1
1
2
1
2
1
5 5
2 1
1 1
1 1
1 2
2 1
2
1
1
2
2
*/
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |