View Code of Problem 5

#include<bits/stdc++.h>
using namespace std;
int main (){
	int t, n, m;
	int a[100010][2];
	scanf("%d", &t);
	while(t--){
		scanf("%d%d", &n, &m);
		for(int i = 0;i < n;i++){
			scanf("%d%d", &a[i][0], &a[i][1]);
		}
		int k = 0;
		for(int i = 0;i < m;i++){
			for(int j = 0;j < n;j++){
				if(a[k][0]<a[j][0]) k=j;
				if(a[k][0]==a[j][0] && a[k][1]<a[j][1]) k=j;
			}
			printf("%d", k+1);
			if(i<m-1) printf(" ");
			a[k][0] = 0;
		}
		printf("\n");
	}
	
	return 0;
}

Double click to view unformatted code.


Back to problem 5