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;
pair<int,int> pics[100005];
int fs[100005];//frame size...
int32_t main(){
ios_base::sync_with_stdio(false);cin.tie(0);
int n,m,lo,hi,mid,ans=0;
cin>>n>>m;
for(int x=0;x<n;x++){
cin>>pics[x].second>>pics[x].first;//size, value...
}
sort(pics,pics+n);//by increasing value, then by size...
for(int x=0;x<m;x++){
cin>>fs[x];
}
sort(fs,fs+m);
for(int x=n-1;x>=0;x--){//only care about size of frame...
//find smallest possible index of frame that can fit painting...
if(pics[x].second>fs[m-1])pics[x].first=INT_MAX;
else{
lo=0;hi=m-1;
while(lo<hi){
mid=lo+(hi-lo)/2;
if(pics[x].second<=fs[mid]){//picture fits in frame
hi=mid;
}else{
lo=mid+1;//exceed frame size
}
}
pics[x].first=lo;
}
pics[x].second=x+1;//the index to rmb...
if(pics[x].first==INT_MAX)continue;
if(ans>m-1-pics[x].first)continue;
else ans++;//take the current thing...
}
cout<<ans;
return 0;
}
/*
3 4
10 20
5 1
3 5
4 6 10 4
*/
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |