#include "bits/stdc++.h"
using namespace std;
#define ar array
#define int long long
signed main(){
ios::sync_with_stdio(0); cin.tie(0);
int n, m; cin>>n>>m;
vector<int> s(n), v(n), c(m), p(n);
for(int i=0;i<n;i++) cin>>s[i]>>v[i], p[i] = i;
sort(p.begin(), p.end(), [&](int i, int j){
return (v[i] < v[j]);
});
for(int i=0, last=0;i<n;){
int j=i;
while(j<n && v[p[i]] == v[p[j]]) j++;
while(i<j) v[p[i++]] = last;
last++;
}
for(int i=0;i<m;i++){
cin>>c[i];
} sort(c.begin(), c.end());
vector<int> left(n);
for(int i=0;i<n;i++){
left[i] = m - (int)(lower_bound(c.begin(), c.end(), s[i]) - c.begin()) - 1;
}
vector<ar<int, 2>> t(n);
for(int i=0;i<n;i++) t[i] = {v[p[i]], left[p[i]]};
for(int i=0;i<n;i++) v[i] = t[i][0], left[i] = t[i][1];
auto check = [&](int k){
vector<int> dp(n);
int mx = 0;
for(int i=0;i<n;i++){
if(left[i] == -1) continue;
dp[i] = mx + 1;
int p = max(1ll, k - left[i]);
if(dp[i] >= p) mx++;
} return (mx >= k);
};
int l = 0, r = n;
while(l < r){
int m = (l + r + 1) >> 1;
if(check(m)) l = m;
else r = m - 1;
}
cout<<l<<"\n";
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |