View Code of Problem 5

import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		int t, n, m, pos = 0;
		int[] a = new int[100000];
		int[] b = new int[100000];
		Scanner cin = new Scanner(System.in);
		t = cin.nextInt();
		while ((t--) > 0) {
			n = cin.nextInt();
			m = cin.nextInt();
			for (int i = 0; i < n; i++) {
				a[i] = cin.nextInt();
				b[i] = cin.nextInt();
			}
			for (int i = 0; i < m; i++) {
				pos = 0;
				for (int j = 1; j < n; j++) {
					if (a[j] > a[pos]) {
						pos = j;
					} else if (a[j] == a[pos] && b[j] > b[pos]) {
						pos = j;
					}

				}
				a[pos] = 0;
				b[pos] = 0;
				if (i < m - 1) {
					System.out.print(pos + 1 + " ");
				}
			}
			System.out.println(pos + 1);
		}

	}

}

Double click to view unformatted code.


Back to problem 5