View Code of Problem 5

#include<iostream>
#include<algorithm>
using namespace std;
struct br
{
	int apple,pear,tag;
};
bool cmp(struct br a, struct br b)
{
	if(a.apple!=b.apple)	return a.apple>b.apple;
	else if(a.pear!=b.pear)	return a.pear>b.pear;
	else	return a.tag<b.tag;
}
int main()
{
	int n;
	cin>>n;
	while(n--){
		int m,p;//有m个篮子,选择p只;
		cin>>m>>p;
		struct br a[m];
		for(int i=0;i<m;++i){
			cin>>a[i].apple>>a[i].pear;	
			a[i].tag=i+1;		
		}
		sort(a,a+m,cmp);
		for(int i=0;i<p;++i){
			if(i==0)	cout<<a[i].tag;
			else	cout<<" "<<a[i].tag;
		}
		cout<<endl;
		 
	}
}

Double click to view unformatted code.


Back to problem 5