# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1143997 | mingga | Exhibition (JOI19_ho_t2) | C++20 | 30 ms | 8264 KiB |
#include "bits/stdc++.h"
using namespace std;
#define ln "\n"
#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define int long long
const int mod = 1e9 + 7;
const int inf = 2e18;
const int N = 1e5 + 7;
int n, m;
struct picture {
int s, v;
bool operator < (const picture& o) const {
if(v == o.v) return s < o.s;
return v < o.v;
}
} a[N];
int b[N];
namespace sub2 {
bool check() {
return n <= 1000 and m <= 1000;
}
int dp[1005][1005];
void solve() {
for(int i = 1; i <= n; i++) {
for(int j = 1; j <= m; j++) {
dp[i][j] = max(dp[i][j - 1], dp[i - 1][j]);
if(b[j] >= a[i].s) {
dp[i][j] = max(dp[i][j], dp[i - 1][j - 1] + 1);
}
}
}
cout << dp[n][m] << ln;
}
}
namespace full {
void solve() {
int ans = 0;
for(int i = n, j = m; i > 0 and j > 0; i--) {
if(a[i].s <= b[j]) {
ans++;
j--;
}
}
cout << ans << ln;
}
}
signed main() {
cin.tie(0) -> sync_with_stdio(0);
#define task ""
if(fopen(task ".INP", "r")) {
freopen(task ".INP", "r", stdin);
freopen(task ".OUT", "w", stdout);
}
cin >> n >> m;
for(int i = 1; i <= n; i++) {
cin >> a[i].s >> a[i].v;
}
for(int i = 1; i <= m; i++) cin >> b[i];
sort(b + 1, b + m + 1);
sort(a + 1, a + n + 1);
if(sub2::check()) sub2::solve();
else full::solve();
cerr << "\nTime: " << clock() * 1000 / CLOCKS_PER_SEC;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |