View Code of Problem 5

package com.zucc.acm;

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 d;
        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++) {
                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;
                if (j < m - 1) {
                    System.out.print(d + 1 + " ");
                } else {
                    System.out.println(d + 1);
                }
            }


        }
    }
}

Double click to view unformatted code.


Back to problem 5