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] = { },flag = 0;
		cin>>x>>y;
	for(int i = 0;i<x;i++)cin>>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[i][0] < a[j][0]) flag = j;
			else if(a[i][0] == a[j][0] && a[i][1] < a[j][1]) flag = j;
		}
		cout<<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