#include <bits/stdc++.h>
#define ll long long
#define ar array
#define db double
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define rint(l, r) uniform_int_distribution<int>(l, r)(rng)
template<typename T> bool ckmin(T &a, const T &b) { return a > b ? a = b, 1 : 0; }
template<typename T> bool ckmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; }
struct seg {
int N; vector<int> tree;
seg(int n) : N(1<<(__lg(n))), tree(2*N) {}
void update(int pos, int x) {
for (int i = pos+N; i; i >>= 1) {
ckmax(tree[i], x);
}
}
int query(int node, int nl, int nr, int ql, int qr) {
if (ql > nr || qr < nl) return 0;
if (ql <= nl && nr <= qr) return tree[node];
int mid = (nl+nr)/2;
return max(query(node*2, nl, mid, ql, qr), query(node*2+1, mid+1, nr, ql, qr));
}
int query(int l, int r) {
return query(1, 0, N-1, l, r);
}
};
void test_case() {
int n, m;
cin >> n >> m;
vector<int> X, Y;
vector<ar<int, 2>> a(n);
for (auto &x : a) cin >> x[0] >> x[1], X.push_back(x[0]), Y.push_back(x[1]);
vector<int> s(m);
for (int &x : s) cin >> x, X.push_back(x);
sort(all(X));
sort(all(Y));
X.erase(unique(all(X)), X.end());
Y.erase(unique(all(Y)), Y.end());
for (auto &x : a) {
x[0] = lower_bound(all(X), x[0]) - X.begin();
x[1] = lower_bound(all(Y), x[1]) - Y.begin();
}
for (int &x : s) {
x = lower_bound(all(X), x) - X.begin();
}
sort(all(a), [&](auto &A, auto &B) { return A[1] < B[1]; });
sort(all(s));
const int N = sz(X);
vector<int> dp(N);
for (int i = n-1; i >= 0; i--) {
auto [x, y] = a[i];
vector<int> dp2(dp);
for (int j = 0; j < N; j++) {
int cnt = dp[j];
if (cnt == m) continue;
int use = s[m - cnt - 1];
if (use >= x) {
ckmax(dp2[use], dp[j] + 1);
}
}
swap(dp, dp2);
}
cout << *max_element(all(dp)) << '\n';
}
int main() {
cin.tie(0)->sync_with_stdio(0);
int t = 1;
// cin >> t;
while (t--) test_case();
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |