View Code of Problem 5

import java.util.Scanner;
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int cishu = sc.nextInt();
		for (int i = 0; i < cishu; i++) {
			int n = sc.nextInt();
			int m = sc.nextInt();
			int a[] = new int[n];
			int b[] = new int[n];
			for (int j = 0; j < a.length; j++) {
				a[j] = sc.nextInt();
				b[j] = sc.nextInt();
			}
			for (int j = 0; j < m; j++) {
				int d = 0;
				for (int k = 0; k < a.length; k++) {
					if (a[k] - a[d] > 0) {
						d = k;
					} else if (a[k] == a[d] && b[k] > b[d] ) {
						d = k;
					}
				}
				a[d]=0;b[d]=0;
				System.out.print(d + 1+" ");
			}
			
		}
	}
}

Double click to view unformatted code.


Back to problem 5