一、题目链接
http://noi.openjudge.cn/ch0110/05/
二、解题思路
三、实施步骤
四、Java程序
import java.util.Arrays;
import java.util.Scanner;
class Volunteer implements Comparable<Volunteer> {
int id;
int score;
public Volunteer(int id, int score) {
this.id = id;
this.score = score;
}
@Override
public int compareTo(Volunteer o) {
if (this.score != o.score) {
return o.score - this.score;
}
return this.id - o.id;
}
@Override
public String toString() {
return id + " " + score;
}
}
public class Main {
public int[] interview(Volunteer[] volunteers, int plan) {
int n = volunteers.length;
int number = (int) (Math.floor(plan * 1.5));
int line;
Arrays.sort(volunteers);
line = volunteers[number - 1].score;
while (number < n && volunteers[number].score == line) {
number++;
}
return new int[]{line, number};
}
public static void main(String[] args) {
Main test = new Main();
Scanner input = new Scanner(System.in);
int n = input.nextInt();
int m = input.nextInt();
Volunteer[] volunteers = new Volunteer[n];
for (int i = 0; i < n; i++) {
int id = input.nextInt();
int score = input.nextInt();
volunteers[i] = new Volunteer(id, score);
}
int[] ans = test.interview(volunteers, m);
System.out.println(ans[0] + " " + ans[1]);
for (int i = 0; i < ans[1]; i++) {
System.out.println(volunteers[i].toString());
}
}
}