#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int, int> pii;
const int MXN = 1005;
int n, m, fr[MXN], dp[MXN][MXN], lastC, ans, pre[MXN];
struct P {
int sz, val;
P() {
sz = 0;
val = 0;
}
P(int _sz, int _val) {
sz = _sz;
val = _val;
}
} pic[MXN];
void getDP(int id) {
// cout << "id: " << id << endl;
lastC = 0;
while (pic[id].sz > fr[lastC]) lastC++;
// cout << "lastC: " << lastC << endl;
// vector<int> avail;
// for (int i = 0; i < id; i++) if (pic[i].val <= pic[id].val) avail.push_back(i);
// cout << "avail: ";
// for (auto &i : avail) cout << i << ' ';
// cout << endl;
for (int i = lastC; i < m; i++) {
// dp[id][i] = 1;
dp[id][i] = max(1LL, pre[i - 1] + 1);
// pre[i] = max(pre[i], dp[id][i]);
// for (auto &j : avail) {
// dp[id][i] = max(dp[id][i], dp[j][i - 1] + 1);
// }
}
for (int i = 0; i < m; i++) pre[i] = max(pre[i], dp[id][i]);
ans = max(ans, dp[id][m - 1]);
}
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cin >> n >> m;
for (int i = 0; i < n; i++) cin >> pic[i].sz >> pic[i].val;
for (int i = 0; i < m; i++) cin >> fr[i];
sort(pic, pic + n, [](P &a, P &b) {
return (a.val == b.val ? a.sz < b.sz : a.val < b.val);
});
sort(fr, fr + m);
fr[m] = LLONG_MAX;
for (int i = 0; i < n; i++) {
getDP(i);
}
// for (int i = 0; i < n; i++) {
// for (int j = 0; j < m; j++) {
// cout << dp[i][j] << ' ';
// }
// cout << endl;
// }
cout << ans << endl;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
0 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
0 ms |
340 KB |
Output is correct |
15 |
Correct |
0 ms |
340 KB |
Output is correct |
16 |
Correct |
0 ms |
340 KB |
Output is correct |
17 |
Correct |
0 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
0 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
0 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
0 ms |
340 KB |
Output is correct |
15 |
Correct |
0 ms |
340 KB |
Output is correct |
16 |
Correct |
0 ms |
340 KB |
Output is correct |
17 |
Correct |
0 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
0 ms |
340 KB |
Output is correct |
20 |
Correct |
5 ms |
7228 KB |
Output is correct |
21 |
Correct |
5 ms |
7272 KB |
Output is correct |
22 |
Correct |
3 ms |
340 KB |
Output is correct |
23 |
Correct |
3 ms |
340 KB |
Output is correct |
24 |
Correct |
5 ms |
8068 KB |
Output is correct |
25 |
Correct |
6 ms |
8020 KB |
Output is correct |
26 |
Correct |
5 ms |
8020 KB |
Output is correct |
27 |
Correct |
3 ms |
340 KB |
Output is correct |
28 |
Correct |
3 ms |
360 KB |
Output is correct |
29 |
Correct |
5 ms |
8184 KB |
Output is correct |
30 |
Correct |
5 ms |
7380 KB |
Output is correct |
31 |
Correct |
5 ms |
7380 KB |
Output is correct |
32 |
Correct |
2 ms |
2388 KB |
Output is correct |
33 |
Correct |
1 ms |
352 KB |
Output is correct |
34 |
Correct |
3 ms |
5460 KB |
Output is correct |
35 |
Correct |
1 ms |
488 KB |
Output is correct |
36 |
Correct |
5 ms |
7380 KB |
Output is correct |
37 |
Correct |
6 ms |
7252 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
0 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
0 ms |
340 KB |
Output is correct |
15 |
Correct |
0 ms |
340 KB |
Output is correct |
16 |
Correct |
0 ms |
340 KB |
Output is correct |
17 |
Correct |
0 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
0 ms |
340 KB |
Output is correct |
20 |
Correct |
5 ms |
7228 KB |
Output is correct |
21 |
Correct |
5 ms |
7272 KB |
Output is correct |
22 |
Correct |
3 ms |
340 KB |
Output is correct |
23 |
Correct |
3 ms |
340 KB |
Output is correct |
24 |
Correct |
5 ms |
8068 KB |
Output is correct |
25 |
Correct |
6 ms |
8020 KB |
Output is correct |
26 |
Correct |
5 ms |
8020 KB |
Output is correct |
27 |
Correct |
3 ms |
340 KB |
Output is correct |
28 |
Correct |
3 ms |
360 KB |
Output is correct |
29 |
Correct |
5 ms |
8184 KB |
Output is correct |
30 |
Correct |
5 ms |
7380 KB |
Output is correct |
31 |
Correct |
5 ms |
7380 KB |
Output is correct |
32 |
Correct |
2 ms |
2388 KB |
Output is correct |
33 |
Correct |
1 ms |
352 KB |
Output is correct |
34 |
Correct |
3 ms |
5460 KB |
Output is correct |
35 |
Correct |
1 ms |
488 KB |
Output is correct |
36 |
Correct |
5 ms |
7380 KB |
Output is correct |
37 |
Correct |
6 ms |
7252 KB |
Output is correct |
38 |
Runtime error |
22 ms |
5772 KB |
Execution killed with signal 11 |
39 |
Halted |
0 ms |
0 KB |
- |