View Code of Problem 5

#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin>>n;
	int x,y;
	while(n--){
		int i;
		int a[1000][2] = { };
		cin>>x>>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 flag = 0;
		for(int j = 0;j<x;j++){
			if(a[flag][0] < a[j][0]) flag = j;
			else if(a[flag][0] == a[j][0] && a[flag][1] < a[j][1]) flag = j;
		}
		printf("%d",flag+1);
		if(i<y-1)cout<<" "; 
		a[flag][0] = -10;
	}
	cout<<endl;		
	}
	
	return 0;
}

Double click to view unformatted code.


Back to problem 5