View Code of Problem 5

#include <stdio.h>
void main(){
	int t, n, m;
	int a[100], b[100];
	scanf("%d", &t);
	while (t--){
		scanf("%d %d", &n, &m);
		for (int i = 0; i < n; i++){
			scanf("%d %d", &a[i], &b[i]);
		}
		for (int j = 0; j < m; j++){
			int max = 0;
			for (int i = 0; i < n; i++){
				if (a[i] > a[max]){
					max = i;
				}
				else if (a[i] == a[max])
				{
					if (b[i] > b[max]){
						max = i;
					}
				}
			}
			if (j < m - 1){
				printf("%d ", max + 1);
			}
			else{
				printf("%d\n", max + 1);
			}
			a[max] = 0;
			b[max] = 0;
		}
	}
}

Double click to view unformatted code.


Back to problem 5