이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
#define all(x) x.begin(), x.end()
#define pb push_back
using namespace std;
using ll = long long;
using vi = vector<ll>;
using pi = pair<ll, ll>;
const int maxn= 1030;
int n, m, dp[maxn][maxn];
vector<pi> a;
vi b;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n >> m;
a.resize(n);
b.resize(m);
for(int i = 0; i < n; i++) cin >> a[i].second >> a[i].first;
for(int i = 0; i < m; i++) cin >> b[i];
sort(all(a));
sort(all(b));
memset(dp, -0x3f, sizeof dp);
dp[0][0] = 0;
for(int i = 0; i <= n; i++) {
for(int j = 0; j <= m; j++) {
dp[i+1][j] = max(dp[i][j], dp[i+1][j]);
dp[i][j+1] = max(dp[i][j], dp[i][j+1]);
if(i<n&&j<m&&a[i].second<=b[j])
dp[i+1][j+1] = max(dp[i+1][j+1], dp[i][j]+1);
}
}
cout << dp[n][m];
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |