#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 |
1 |
Correct |
5 ms |
8140 KB |
Output is correct |
2 |
Correct |
4 ms |
8140 KB |
Output is correct |
3 |
Correct |
6 ms |
8152 KB |
Output is correct |
4 |
Correct |
4 ms |
8140 KB |
Output is correct |
5 |
Correct |
4 ms |
8140 KB |
Output is correct |
6 |
Correct |
4 ms |
8140 KB |
Output is correct |
7 |
Correct |
4 ms |
8140 KB |
Output is correct |
8 |
Correct |
4 ms |
8140 KB |
Output is correct |
9 |
Correct |
3 ms |
8140 KB |
Output is correct |
10 |
Correct |
3 ms |
8140 KB |
Output is correct |
11 |
Correct |
4 ms |
8140 KB |
Output is correct |
12 |
Correct |
3 ms |
8140 KB |
Output is correct |
13 |
Correct |
4 ms |
8140 KB |
Output is correct |
14 |
Correct |
3 ms |
8140 KB |
Output is correct |
15 |
Correct |
3 ms |
8140 KB |
Output is correct |
16 |
Correct |
5 ms |
8140 KB |
Output is correct |
17 |
Correct |
4 ms |
8140 KB |
Output is correct |
18 |
Correct |
3 ms |
8108 KB |
Output is correct |
19 |
Correct |
4 ms |
8140 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
8140 KB |
Output is correct |
2 |
Correct |
4 ms |
8140 KB |
Output is correct |
3 |
Correct |
6 ms |
8152 KB |
Output is correct |
4 |
Correct |
4 ms |
8140 KB |
Output is correct |
5 |
Correct |
4 ms |
8140 KB |
Output is correct |
6 |
Correct |
4 ms |
8140 KB |
Output is correct |
7 |
Correct |
4 ms |
8140 KB |
Output is correct |
8 |
Correct |
4 ms |
8140 KB |
Output is correct |
9 |
Correct |
3 ms |
8140 KB |
Output is correct |
10 |
Correct |
3 ms |
8140 KB |
Output is correct |
11 |
Correct |
4 ms |
8140 KB |
Output is correct |
12 |
Correct |
3 ms |
8140 KB |
Output is correct |
13 |
Correct |
4 ms |
8140 KB |
Output is correct |
14 |
Correct |
3 ms |
8140 KB |
Output is correct |
15 |
Correct |
3 ms |
8140 KB |
Output is correct |
16 |
Correct |
5 ms |
8140 KB |
Output is correct |
17 |
Correct |
4 ms |
8140 KB |
Output is correct |
18 |
Correct |
3 ms |
8108 KB |
Output is correct |
19 |
Correct |
4 ms |
8140 KB |
Output is correct |
20 |
Correct |
14 ms |
8396 KB |
Output is correct |
21 |
Correct |
13 ms |
8396 KB |
Output is correct |
22 |
Correct |
12 ms |
8296 KB |
Output is correct |
23 |
Correct |
11 ms |
8396 KB |
Output is correct |
24 |
Correct |
14 ms |
8392 KB |
Output is correct |
25 |
Correct |
13 ms |
8400 KB |
Output is correct |
26 |
Correct |
13 ms |
8396 KB |
Output is correct |
27 |
Correct |
11 ms |
8408 KB |
Output is correct |
28 |
Correct |
11 ms |
8396 KB |
Output is correct |
29 |
Correct |
11 ms |
8300 KB |
Output is correct |
30 |
Correct |
13 ms |
8392 KB |
Output is correct |
31 |
Correct |
14 ms |
8396 KB |
Output is correct |
32 |
Correct |
4 ms |
8268 KB |
Output is correct |
33 |
Correct |
4 ms |
8264 KB |
Output is correct |
34 |
Correct |
7 ms |
8268 KB |
Output is correct |
35 |
Correct |
4 ms |
8268 KB |
Output is correct |
36 |
Correct |
13 ms |
8404 KB |
Output is correct |
37 |
Correct |
15 ms |
8408 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
8140 KB |
Output is correct |
2 |
Correct |
4 ms |
8140 KB |
Output is correct |
3 |
Correct |
6 ms |
8152 KB |
Output is correct |
4 |
Correct |
4 ms |
8140 KB |
Output is correct |
5 |
Correct |
4 ms |
8140 KB |
Output is correct |
6 |
Correct |
4 ms |
8140 KB |
Output is correct |
7 |
Correct |
4 ms |
8140 KB |
Output is correct |
8 |
Correct |
4 ms |
8140 KB |
Output is correct |
9 |
Correct |
3 ms |
8140 KB |
Output is correct |
10 |
Correct |
3 ms |
8140 KB |
Output is correct |
11 |
Correct |
4 ms |
8140 KB |
Output is correct |
12 |
Correct |
3 ms |
8140 KB |
Output is correct |
13 |
Correct |
4 ms |
8140 KB |
Output is correct |
14 |
Correct |
3 ms |
8140 KB |
Output is correct |
15 |
Correct |
3 ms |
8140 KB |
Output is correct |
16 |
Correct |
5 ms |
8140 KB |
Output is correct |
17 |
Correct |
4 ms |
8140 KB |
Output is correct |
18 |
Correct |
3 ms |
8108 KB |
Output is correct |
19 |
Correct |
4 ms |
8140 KB |
Output is correct |
20 |
Correct |
14 ms |
8396 KB |
Output is correct |
21 |
Correct |
13 ms |
8396 KB |
Output is correct |
22 |
Correct |
12 ms |
8296 KB |
Output is correct |
23 |
Correct |
11 ms |
8396 KB |
Output is correct |
24 |
Correct |
14 ms |
8392 KB |
Output is correct |
25 |
Correct |
13 ms |
8400 KB |
Output is correct |
26 |
Correct |
13 ms |
8396 KB |
Output is correct |
27 |
Correct |
11 ms |
8408 KB |
Output is correct |
28 |
Correct |
11 ms |
8396 KB |
Output is correct |
29 |
Correct |
11 ms |
8300 KB |
Output is correct |
30 |
Correct |
13 ms |
8392 KB |
Output is correct |
31 |
Correct |
14 ms |
8396 KB |
Output is correct |
32 |
Correct |
4 ms |
8268 KB |
Output is correct |
33 |
Correct |
4 ms |
8264 KB |
Output is correct |
34 |
Correct |
7 ms |
8268 KB |
Output is correct |
35 |
Correct |
4 ms |
8268 KB |
Output is correct |
36 |
Correct |
13 ms |
8404 KB |
Output is correct |
37 |
Correct |
15 ms |
8408 KB |
Output is correct |
38 |
Incorrect |
55 ms |
13492 KB |
Output isn't correct |
39 |
Halted |
0 ms |
0 KB |
- |