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();
		int shu = 0;
		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 q = 0; q < m; q++) {
				for (int l = 0; l < a.length; l++) {
					if (a[shu] < a[l]) {
						shu = l;
					} else if (a[shu] == a[l] && b[shu] < b[l]) {
						shu = l;
					}
				}	
				System.out.print(shu + 1 + " ");
				a[shu]=0;b[shu]=0;
			}
			System.out.println();		
		}
	}
}

Double click to view unformatted code.


Back to problem 5