View Code of Problem 5

#include<bits/stdc++.h>
using namespace std;
int main(){
	int t;
	cin>>t;
	while(t--){
		int n,m,num[1001][2] = { };
		cin>>n>>m;
		for(int i = 0;i<n;i++)cin>>num[i][0]>>num[i][1];
		for(int i = 0;i<m;i++){
			int max = 0;
			for(int j = 0;j<n;j++){
				if(num[max][0] < num[j][0])max = j;
				else if(num[max][0] == num[j][0]  && num[max][1] < num[j][1])max = j;
			}
			cout<<max+1;
			if(i!=(m-1))cout<<" ";
			num[max][0] = -100;
		}
		
		cout<<endl;
	}
		
	
	
	
	
	
	
} 

Double click to view unformatted code.


Back to problem 5