View Code of Problem 5

#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,x,y;
	scanf("%d",&n);
	while(n--){   
		int a[1000][2] = { };
		scanf("%d%d",&x,&y); //y是篮子的个数 
		for(int i = 1;i<=x;i++)scanf("%d%d",&a[i][1],&a[i][2]);
		for(int i = 1;i<=y;i++){
			int k = 1;
			for(int j = 1;j<=x;j++){
				if(a[k][1] < a[j][1]) k = j;
				if(a[k][1] == a[j][1] && a[k][2]<a[j][2])k = j;
			}
			printf("%d",k);
			a[k][1] = -1;
			if(i!=y)cout<<" ";					
		}
		cout<<endl;
	}
	return 0;
}

Double click to view unformatted code.


Back to problem 5