View Code of Problem 5

#include<iostream>

using namespace std;

int main(){
	int t;
	int n, m;
	cin>>t;
	while(t--){
		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 ans;
			int maxans[2]={0,0};
			for(int j=0;j<n;++j){
				if((a[j]>maxans[0]) || (a[j]==maxans[0] && b[j]>maxans[1])){
					ans=j;
					maxans[0]=a[j];
					maxans[1]=b[j]; 
				}
			}
			if(i!=0){
				cout<<' '; 
			}
			cout<<ans+1;
			a[ans]=-1;
		}
		cout<<endl;
	}
	return 0;
} 

Double click to view unformatted code.


Back to problem 5