View Code of Problem 5

#include<cstdio>
#include<vector>
#include<algorithm>
using namespace std;
typedef struct basket{
	int apple,pear;
	int no;
}lz; 
bool cmp(lz a,lz 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.no<b.no;
	}
}
int main(){
	int t;
	//freopen("5.txt","r",stdin);
	scanf("%d",&t);
	for(int i=0;i<t;i++){
		int n,m;
		scanf("%d %d",&n,&m);
		vector<lz> vt(n+1);
		for(int j=1;j<=n;j++){
			scanf("%d %d",&vt[j].apple,&vt[j].pear);
			vt[j].no=j;
		}
		sort(vt.begin(),vt.end(),cmp);
		for(int k=0;k<m;k++){
			if(k!=m-1)	printf("%d ",vt[k].no);
			else	printf("%d",vt[k].no);
		}
		printf("\n");
	}	
	return 0;
}

Double click to view unformatted code.


Back to problem 5