이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
#define sz(x) (int) (x).size()
int n, m;
pair<int, int> p[100005];
int f[100005];
int memo[1005][1005];
int dp(int i, int j){
if(memo[i][j]!=-1){return memo[i][j];}
if(i==n||j==m){return memo[i][j]= 0;}
if(p[i].second<=f[j]){
return memo[i][j]= max(dp(i+1, j+1)+1, max(dp(i, j+1), dp(i+1,j)));
}else{
return memo[i][j]= max(dp(i, j+1), dp(i+1,j));
}
}
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
cin >> n >> m;
for(int i=0; i<n; i++){
int a, b; cin >> a >> b;
p[i]= make_pair(b, a);
}
for(int i=0; i<m; i++){cin >> f[i];}
sort(f, f+m);
sort(p, p+n);
memset(memo, -1, sizeof(memo));
int ans= dp(0, 0);
cout << ans << endl;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |