This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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);
sort(p.begin(), p.end(), [&](int i, int j){
if(v[i] != v[j]) return v[i] < v[j];
return left[i] > left[j];
});
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){
int mx = 0;
for(int i=0;i<n;i++){
if(left[i] == -1) continue;
int p = max(1ll, k - left[i]);
if(p <= mx + 1) 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";
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |