输入样例:
5 6
3 7 9 6 4
1 2 3 4 5 6
样例输出:
3
0
0
2
1
1,M:此M漂亮的一塌糊涂,美啊!
2,sort()+sort())回到原始排列顺序
#include <bits/stdc++.h>
using namespace std;
int M = 0x3f3f3f; //此M漂亮的一塌糊涂
struct st{
int height;
int num;
int co; //小苹友得到的气球数
}a[1005];
int b[1005];
bool comp(st a,st b){
return a.height < b.height;
}
bool comp1(st a,st b){
return a.num < b.num;
}
int main(){
int m,n;
cin >> n >> m;
for(int i = 1; i <= n; i++){
cin >> a[i].height;
a[i].num = i;
a[i].co = 0;
}
for(int i = 1 ; i <= m; i++){
cin >> b[i];
}
sort(a+1,a+n+1,comp);
//cout << a[2].num << a[2].height << endl;
for(int i = 1; i <= n; i++){
for(int j = 1; j <= m; j++){
if(a[i].height >= b[j]){
a[i].co++;
b[j] = M; //美啊,代表气球已被摘走。
}
}
}
sort(a+1,a+n+1,comp1); //顺序要回到原始模样
for(int i = 1; i <= n; i++){
cout << a[i].co <<endl;
}
return 0;
}