#include<bits/stdc++.h>
using namespace std;
#define i64 long long
#define mp make_pair
#define pb push_back
#define all(x) (x).begin(), (x).end()
void Maximize(pair<int, int> &a, pair<int, int> b) {
if (a.first < b.first) a = b;
else if (a.first == b.first) a.second = min(a.second, b.second);
}
void Solve(void) {
int N, M; cin >> N >> M;
vector<pair<int, int>> pics(N), f(N + 2, mp(-1, -1));
for (int i = 0; i < N; i ++) {
cin >> pics[i].second >> pics[i].first;
}
vector<int> frames;
for (int i = 0; i < M; i ++) {
int x; cin >> x;
frames.pb(x);
} sort(all(frames));
sort(all(pics));
stack<int> s;
int ans = 0;
for (int i = 0; i < N; i ++) {
// cout << pics[i].first << " " << pics[i].second << "\n";
while (!s.empty() && pics[s.top()].second > pics[i].second) {
if (f[s.top()].second < M - 1 && f[s.top()].first != -1) {
Maximize(f[i], mp(f[s.top()].first + 1, f[s.top()].second + 1));
}
s.pop();
}
int p = lower_bound(all(frames), pics[i].second) - frames.begin();
if (p != M) {
Maximize(f[i], mp(1, p));
if (!s.empty()) {
int curp = max(f[s.top()].second + 1, p);
if (curp < M && f[s.top()].first != -1) {
Maximize(f[i], mp(f[s.top()].first + 1, curp));
}
}
}
s.push(i);
ans = max(ans, f[i].first);
// cout << pics[i].second << " " << f[i].first << " " << f[i].second << "\n";
}
cout << ans << "\n";
}
signed main() {
ios_base::sync_with_stdio(false); cin.tie(0);
int Tests = 1; // cin >> Tests;
while (Tests --) {
Solve();
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |