View Code of Problem 5

#include<iostream>
#include<algorithm>
using namespace std;
int main(){
	int n,t,m;
	cin>>t;
	for(int i = 0;i<t;i++){ //组数 
		cin>>n>>m;
		int a[n] = { },b[n] = { };
		for(int i = 0;i<n;i++)cin>>a[i]>>b[i];
		for(int i = 0;i<m;i++){
			int max = 0;
			for(int j = 0;j < n;j++){
				if(a[j] > a[max])max = j;
				else if(a[j] == a[max] && b[j] > b[max])max = j;
			}
			cout<<max+1;
			a[max] = -111;
			if(i != m - 1)cout<<" ";
		}
		cout<<endl;
	}
	return 0;
} 

Double click to view unformatted code.


Back to problem 5