Description:
jlh很喜欢吃水果,苹果是他最喜欢的,其次是梨。他天天想着吃水果,竟然感动了女娲大神,女娲大神给了他n个篮子,让他选择其中的m个(m<=n)个篮子。每个篮子里有a个苹果和b个梨。请你们帮jlh选择篮子吧。
Input:
输入一个t(t<=10),表示有t组测试数据,再输入n和m(0=<m<=n<=100000),接下来的n行,输入a和b表示苹果和梨的数量。
Output:
按jlh选择的顺序(先选苹果多的,苹果数量相同选梨多的,两者相同选序号小的)篮子的序号(1-n),m个数用空格隔开。
Sample Input:
2 2 1 2 0 1 4 3 2 3 4 2 6 3 5
Sample Output:
1 3 1
#include<algorithm>
#include<iostream>
using namespace std;
int a[100010][2];
int main()
{
int t,n,m;
cin>>t;
while(t--)
{
cin>>n>>m;
for(int i=1;i<=n;i++)
{
cin>>a[i][0]>>a[i][1];
}
int maxapple,maxpear,pos;
for(int k=0;k<m;k++){ //循环m次
maxapple=a[1][0];
maxpear=a[1][1];
pos=1;
for(int j=1;j<=n;j++)
{
if(maxapple<a[j][0]) //苹果数量不同时
{
maxapple=a[j][0];
maxpear=a[j][1];
pos=j;
}else if(maxapple==a[j][0]){ //苹果数量相同时
if(maxpear<a[j][1])
{
maxpear=a[j][1];
pos=j;
}
}
}
a[pos][0]=-1; a[pos][1]=-1; //已选出的设值为负
if(k==0)
{
cout<<pos;
}
else{
cout<<' '<<pos;
}
}
cout<<endl;
}
return 0;
}