View Code of Problem 5

package com.zucc.acm;

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int t = scanner.nextInt();
        for (int i = 0; i < t; i++) {
            int n, m;
            n = scanner.nextInt();
            m = scanner.nextInt();
            int[][] temp = new int[n][2];
            for (int j = 0; j < n; j++) {
                temp[j][0] = scanner.nextInt();
                temp[j][1] = scanner.nextInt();
            }
            for (int j = 0; j < m; j++) {
                Main.select(temp);
                if (j!=m-1){
                    System.out.print(" ");
                }else {
                    System.out.println("");
                }
            }
        }
    }

    public static void select(int[][] values) {
        int max=0;
        for (int i = 1; i < values.length; i++) {
            if (values[i][0]>values[max][0]){
                max=i;
            }else if (values[i][0]==values[max][0]){
                if (values[i][1]>values[max][1]){
                    max=i;
                }
            }
        }
        values[max][0]=0;
        values[max][1]=0;
        System.out.print(max+1);
    }
}

Double click to view unformatted code.


Back to problem 5