#include <bits/stdc++.h>
using namespace std;
const long long INFll = (long long) 1e18 + 10;
const int INFii = (int) 1e9 + 10;
typedef long long ll;
typedef int ii;
typedef long double dbl;
#define endl '\n'
#define sc second
#define fr first
#define mp make_pair
#define pb push_back
#define all(x) x.begin(), x.end()
#define maxn 1010
ii n, m, dp[maxn][maxn], c[maxn];
pair<ii,ii> p[maxn];
ii sol(ii i, ii j) {
if(i == n+1 || j == m+1) return 0;
if(dp[i][j] != -1) return dp[i][j];
ii ans = 0;
ans = max(ans,sol(i+1,j));
ans = max(ans,sol(i,j+1));
if(p[i].sc <= c[j]) {
ans = max(ans,sol(i+1,j+1)+1);
}
return dp[i][j] = ans;
}
int main() {
ios::sync_with_stdio(false); cin.tie(0);
//freopen("in.in", "r", stdin);
//freopen("out.out", "w", stdout);
cin >> n >> m;
for(ii i = 1; i <= n; i++) {
cin >> p[i].sc >> p[i].fr;
}
for(ii i = 1; i <= m; i++) {
cin >> c[i];
}
for(ii i = 1; i <= n; i++) {
for(ii j = 1; j <= m; j++) {
dp[i][j] = -1;
}
}
sort(p+1,p+1+n);
sort(c+1,c+1+m);
cout << sol(1,1) << endl;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
0 ms |
324 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
0 ms |
332 KB |
Output is correct |
10 |
Correct |
0 ms |
332 KB |
Output is correct |
11 |
Correct |
0 ms |
332 KB |
Output is correct |
12 |
Correct |
0 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
316 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
1 ms |
320 KB |
Output is correct |
17 |
Correct |
1 ms |
332 KB |
Output is correct |
18 |
Correct |
1 ms |
316 KB |
Output is correct |
19 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
0 ms |
324 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
0 ms |
332 KB |
Output is correct |
10 |
Correct |
0 ms |
332 KB |
Output is correct |
11 |
Correct |
0 ms |
332 KB |
Output is correct |
12 |
Correct |
0 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
316 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
1 ms |
320 KB |
Output is correct |
17 |
Correct |
1 ms |
332 KB |
Output is correct |
18 |
Correct |
1 ms |
316 KB |
Output is correct |
19 |
Correct |
1 ms |
332 KB |
Output is correct |
20 |
Correct |
12 ms |
4428 KB |
Output is correct |
21 |
Correct |
13 ms |
4464 KB |
Output is correct |
22 |
Correct |
13 ms |
4428 KB |
Output is correct |
23 |
Correct |
14 ms |
4428 KB |
Output is correct |
24 |
Correct |
13 ms |
4464 KB |
Output is correct |
25 |
Correct |
15 ms |
4464 KB |
Output is correct |
26 |
Correct |
12 ms |
4428 KB |
Output is correct |
27 |
Correct |
13 ms |
4464 KB |
Output is correct |
28 |
Correct |
15 ms |
4464 KB |
Output is correct |
29 |
Correct |
16 ms |
4428 KB |
Output is correct |
30 |
Correct |
16 ms |
4448 KB |
Output is correct |
31 |
Correct |
12 ms |
4428 KB |
Output is correct |
32 |
Correct |
4 ms |
4300 KB |
Output is correct |
33 |
Correct |
1 ms |
332 KB |
Output is correct |
34 |
Correct |
6 ms |
4300 KB |
Output is correct |
35 |
Correct |
1 ms |
460 KB |
Output is correct |
36 |
Correct |
14 ms |
4428 KB |
Output is correct |
37 |
Correct |
12 ms |
4432 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
0 ms |
324 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
0 ms |
332 KB |
Output is correct |
10 |
Correct |
0 ms |
332 KB |
Output is correct |
11 |
Correct |
0 ms |
332 KB |
Output is correct |
12 |
Correct |
0 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
316 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
1 ms |
320 KB |
Output is correct |
17 |
Correct |
1 ms |
332 KB |
Output is correct |
18 |
Correct |
1 ms |
316 KB |
Output is correct |
19 |
Correct |
1 ms |
332 KB |
Output is correct |
20 |
Correct |
12 ms |
4428 KB |
Output is correct |
21 |
Correct |
13 ms |
4464 KB |
Output is correct |
22 |
Correct |
13 ms |
4428 KB |
Output is correct |
23 |
Correct |
14 ms |
4428 KB |
Output is correct |
24 |
Correct |
13 ms |
4464 KB |
Output is correct |
25 |
Correct |
15 ms |
4464 KB |
Output is correct |
26 |
Correct |
12 ms |
4428 KB |
Output is correct |
27 |
Correct |
13 ms |
4464 KB |
Output is correct |
28 |
Correct |
15 ms |
4464 KB |
Output is correct |
29 |
Correct |
16 ms |
4428 KB |
Output is correct |
30 |
Correct |
16 ms |
4448 KB |
Output is correct |
31 |
Correct |
12 ms |
4428 KB |
Output is correct |
32 |
Correct |
4 ms |
4300 KB |
Output is correct |
33 |
Correct |
1 ms |
332 KB |
Output is correct |
34 |
Correct |
6 ms |
4300 KB |
Output is correct |
35 |
Correct |
1 ms |
460 KB |
Output is correct |
36 |
Correct |
14 ms |
4428 KB |
Output is correct |
37 |
Correct |
12 ms |
4432 KB |
Output is correct |
38 |
Runtime error |
54 ms |
11364 KB |
Execution killed with signal 11 |
39 |
Halted |
0 ms |
0 KB |
- |