#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int maxn = 1e5+5;
int N, M;
int frames[maxn];
int dp[maxn];
int main()
{
cin >> N >> M;
vector<pair<int,int>> pictures;
for (int i = 0; i < N; i++) {
int a, b; cin >> a >> b;
pictures.push_back({a,b});
}
//coordinate compress values
sort(pictures.begin(),pictures.end(),[](auto a, auto b) {
return a.second < b.second;
});
map<int,int> comp;
int c = 1;
for (auto& p: pictures) {
if (comp.count(p.second)) p.second = comp[p.second];
else p.second = comp[p.second] = c++;
}
sort(pictures.begin(),pictures.end());
for (int i = 1; i <= M; i++) cin >> frames[i];
sort(frames+1,frames+M+1);
int framePtr = M; //points to one-less-than smallest frame that >= current sz
int ans = 0;
for (int i = N - 1; i >= 0; i--) {
int sz = pictures[i].first;
int val = pictures[i].second;
while (frames[framePtr] >= sz) {
framePtr--;
if (framePtr == 0) break;
}
if (framePtr + 1 == M + 1 || frames[framePtr+1] < sz) continue;
//cout << sz << ": " << framePtr + 1 << ' ' << frames[framePtr+1] << '\n';
int b = M - framePtr;
//cout << i << ": " << b << '\n';
dp[i] = 1;
for (int j = i + 1; j < N; j++) {
if (pictures[j].second >= val && dp[j] <= b - 1) {
dp[i] = min(max(dp[i],min(b-1,dp[j]) + 1),M);
}
}
//cout << i << ": " << dp[i] << '\n';
ans = max(ans,dp[i]);
}
cout << ans << '\n';
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Correct |
3 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
384 KB |
Output is correct |
5 |
Incorrect |
2 ms |
256 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Correct |
3 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
384 KB |
Output is correct |
5 |
Incorrect |
2 ms |
256 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Correct |
3 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
384 KB |
Output is correct |
5 |
Incorrect |
2 ms |
256 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |