有 n 名同学去逛商店,店里有 m 个物品,第 i 人有 wi 块钱,第 i 个物品价格 ci 元。
每个人至多买一个物品,每个物品只能被买一次,问最多有多少人能买到物品。
对于所有数据,n,m≤105,ci≤109。
输入格式
输入共 3 行。
第 1 行输入 2 个正整数 n,m。
第 2行输入n 个整数w1…wn,w_iwi 表示第 i 人的钱。
第 3 行输入 m 个整数 c1…cm,ci 表示第 i 个物品的价格。
输出格式
对于所有数据,n,m≤ ci≤109。
输入输出样例
输入 #1复制
15 20 4 3 9 10 7 7 5 3 6 1 8 6 6 1 5 12 4 1 9 8 5 8 6 4 5 18 8 14 9 9 7 20 11 8 19输出 #1复制
10
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
int n,m,a[100010],b[100010],ans=0;
scanf("%d%d",&n,&m);
for(int i=1;i<=n;i++){
scanf("%d",&a[i]);
}
for(int i=1;i<=m;i++){
scanf("%d",&b[i]);
}
sort(a+1,a+n+1);
sort(b+1,b+m+1);
int k=1;
for(int i=1;i<=n;i++)
if(a[i]>=b[k])
ans++,k++;
cout<<ans;
return 0;
}