#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 |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
5 ms |
376 KB |
Output is correct |
3 |
Correct |
5 ms |
248 KB |
Output is correct |
4 |
Correct |
4 ms |
376 KB |
Output is correct |
5 |
Correct |
5 ms |
376 KB |
Output is correct |
6 |
Correct |
5 ms |
376 KB |
Output is correct |
7 |
Correct |
5 ms |
376 KB |
Output is correct |
8 |
Correct |
5 ms |
376 KB |
Output is correct |
9 |
Correct |
5 ms |
376 KB |
Output is correct |
10 |
Correct |
5 ms |
376 KB |
Output is correct |
11 |
Correct |
5 ms |
376 KB |
Output is correct |
12 |
Correct |
5 ms |
376 KB |
Output is correct |
13 |
Correct |
5 ms |
376 KB |
Output is correct |
14 |
Correct |
5 ms |
376 KB |
Output is correct |
15 |
Correct |
5 ms |
504 KB |
Output is correct |
16 |
Correct |
5 ms |
376 KB |
Output is correct |
17 |
Correct |
5 ms |
376 KB |
Output is correct |
18 |
Correct |
5 ms |
376 KB |
Output is correct |
19 |
Correct |
5 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
5 ms |
376 KB |
Output is correct |
3 |
Correct |
5 ms |
248 KB |
Output is correct |
4 |
Correct |
4 ms |
376 KB |
Output is correct |
5 |
Correct |
5 ms |
376 KB |
Output is correct |
6 |
Correct |
5 ms |
376 KB |
Output is correct |
7 |
Correct |
5 ms |
376 KB |
Output is correct |
8 |
Correct |
5 ms |
376 KB |
Output is correct |
9 |
Correct |
5 ms |
376 KB |
Output is correct |
10 |
Correct |
5 ms |
376 KB |
Output is correct |
11 |
Correct |
5 ms |
376 KB |
Output is correct |
12 |
Correct |
5 ms |
376 KB |
Output is correct |
13 |
Correct |
5 ms |
376 KB |
Output is correct |
14 |
Correct |
5 ms |
376 KB |
Output is correct |
15 |
Correct |
5 ms |
504 KB |
Output is correct |
16 |
Correct |
5 ms |
376 KB |
Output is correct |
17 |
Correct |
5 ms |
376 KB |
Output is correct |
18 |
Correct |
5 ms |
376 KB |
Output is correct |
19 |
Correct |
5 ms |
376 KB |
Output is correct |
20 |
Correct |
6 ms |
380 KB |
Output is correct |
21 |
Correct |
5 ms |
376 KB |
Output is correct |
22 |
Correct |
6 ms |
376 KB |
Output is correct |
23 |
Correct |
6 ms |
376 KB |
Output is correct |
24 |
Correct |
6 ms |
376 KB |
Output is correct |
25 |
Correct |
6 ms |
376 KB |
Output is correct |
26 |
Correct |
6 ms |
376 KB |
Output is correct |
27 |
Correct |
6 ms |
376 KB |
Output is correct |
28 |
Correct |
7 ms |
376 KB |
Output is correct |
29 |
Correct |
5 ms |
376 KB |
Output is correct |
30 |
Correct |
6 ms |
376 KB |
Output is correct |
31 |
Correct |
6 ms |
376 KB |
Output is correct |
32 |
Correct |
5 ms |
376 KB |
Output is correct |
33 |
Correct |
5 ms |
380 KB |
Output is correct |
34 |
Correct |
6 ms |
376 KB |
Output is correct |
35 |
Correct |
5 ms |
376 KB |
Output is correct |
36 |
Correct |
7 ms |
388 KB |
Output is correct |
37 |
Correct |
6 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
5 ms |
376 KB |
Output is correct |
3 |
Correct |
5 ms |
248 KB |
Output is correct |
4 |
Correct |
4 ms |
376 KB |
Output is correct |
5 |
Correct |
5 ms |
376 KB |
Output is correct |
6 |
Correct |
5 ms |
376 KB |
Output is correct |
7 |
Correct |
5 ms |
376 KB |
Output is correct |
8 |
Correct |
5 ms |
376 KB |
Output is correct |
9 |
Correct |
5 ms |
376 KB |
Output is correct |
10 |
Correct |
5 ms |
376 KB |
Output is correct |
11 |
Correct |
5 ms |
376 KB |
Output is correct |
12 |
Correct |
5 ms |
376 KB |
Output is correct |
13 |
Correct |
5 ms |
376 KB |
Output is correct |
14 |
Correct |
5 ms |
376 KB |
Output is correct |
15 |
Correct |
5 ms |
504 KB |
Output is correct |
16 |
Correct |
5 ms |
376 KB |
Output is correct |
17 |
Correct |
5 ms |
376 KB |
Output is correct |
18 |
Correct |
5 ms |
376 KB |
Output is correct |
19 |
Correct |
5 ms |
376 KB |
Output is correct |
20 |
Correct |
6 ms |
380 KB |
Output is correct |
21 |
Correct |
5 ms |
376 KB |
Output is correct |
22 |
Correct |
6 ms |
376 KB |
Output is correct |
23 |
Correct |
6 ms |
376 KB |
Output is correct |
24 |
Correct |
6 ms |
376 KB |
Output is correct |
25 |
Correct |
6 ms |
376 KB |
Output is correct |
26 |
Correct |
6 ms |
376 KB |
Output is correct |
27 |
Correct |
6 ms |
376 KB |
Output is correct |
28 |
Correct |
7 ms |
376 KB |
Output is correct |
29 |
Correct |
5 ms |
376 KB |
Output is correct |
30 |
Correct |
6 ms |
376 KB |
Output is correct |
31 |
Correct |
6 ms |
376 KB |
Output is correct |
32 |
Correct |
5 ms |
376 KB |
Output is correct |
33 |
Correct |
5 ms |
380 KB |
Output is correct |
34 |
Correct |
6 ms |
376 KB |
Output is correct |
35 |
Correct |
5 ms |
376 KB |
Output is correct |
36 |
Correct |
7 ms |
388 KB |
Output is correct |
37 |
Correct |
6 ms |
376 KB |
Output is correct |
38 |
Correct |
191 ms |
5620 KB |
Output is correct |
39 |
Correct |
116 ms |
5620 KB |
Output is correct |
40 |
Correct |
109 ms |
5620 KB |
Output is correct |
41 |
Correct |
186 ms |
5620 KB |
Output is correct |
42 |
Correct |
105 ms |
5748 KB |
Output is correct |
43 |
Correct |
103 ms |
5620 KB |
Output is correct |
44 |
Correct |
153 ms |
5620 KB |
Output is correct |
45 |
Correct |
275 ms |
5492 KB |
Output is correct |
46 |
Correct |
133 ms |
5492 KB |
Output is correct |
47 |
Correct |
271 ms |
5236 KB |
Output is correct |
48 |
Correct |
139 ms |
5108 KB |
Output is correct |
49 |
Correct |
140 ms |
4980 KB |
Output is correct |
50 |
Correct |
102 ms |
4724 KB |
Output is correct |
51 |
Correct |
118 ms |
5600 KB |
Output is correct |
52 |
Correct |
122 ms |
5616 KB |
Output is correct |
53 |
Correct |
128 ms |
5620 KB |
Output is correct |
54 |
Correct |
87 ms |
5620 KB |
Output is correct |
55 |
Correct |
187 ms |
5520 KB |
Output is correct |
56 |
Correct |
65 ms |
3704 KB |
Output is correct |
57 |
Correct |
37 ms |
2296 KB |
Output is correct |
58 |
Correct |
50 ms |
3704 KB |
Output is correct |
59 |
Correct |
130 ms |
3704 KB |
Output is correct |
60 |
Correct |
39 ms |
2292 KB |
Output is correct |
61 |
Correct |
80 ms |
3828 KB |
Output is correct |
62 |
Correct |
238 ms |
5620 KB |
Output is correct |
63 |
Correct |
246 ms |
5620 KB |
Output is correct |
64 |
Correct |
249 ms |
5620 KB |
Output is correct |
65 |
Correct |
253 ms |
5616 KB |
Output is correct |
66 |
Correct |
249 ms |
5620 KB |
Output is correct |
67 |
Correct |
247 ms |
5620 KB |
Output is correct |
68 |
Correct |
243 ms |
5620 KB |
Output is correct |
69 |
Correct |
252 ms |
5620 KB |
Output is correct |
70 |
Correct |
233 ms |
5620 KB |
Output is correct |
71 |
Correct |
236 ms |
5620 KB |
Output is correct |
72 |
Correct |
183 ms |
5624 KB |
Output is correct |
73 |
Correct |
156 ms |
5620 KB |
Output is correct |