Submission #526383

#TimeUsernameProblemLanguageResultExecution timeMemory
526383bebecanvasExhibition (JOI19_ho_t2)C++14
50 / 100
55 ms13492 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...