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 = 0;i<x;i++)scanf("%d%d",&a[i][0],&a[i][1]);
		for(int i = 0;i<y;i++){
			int k = 0;
			for(int j = 0;j<x;j++){
				if(a[k][0] < a[j][0]) k = j;
				if(a[k][0] == a[j][0] && a[k][1]<a[j][1])k = j;
			}
			printf("%d",k+1);
			a[k][0] = -1;
			if(i<y-1)cout<<" ";					
		}
		cout<<endl;
	}
	return 0;
}

Double click to view unformatted code.


Back to problem 5