题解 | 分数线划定
分数线划定
https://www.nowcoder.com/practice/2395fa7b6c6e452e8d8310a7cfdbe902
import java.util.*;
// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
int m = in.nextInt();
int t = (int) (m * 1.5);
List<Candidate> candidates = new ArrayList<>();
for(int i = 0; i < n; i++) {
int k = in.nextInt();
int s = in.nextInt();
candidates.add(new Candidate(k, s));
}
// 排序
candidates.sort((o1, o2) -> {
return o1.score != o2.score ? o2.score.compareTo(o1.score) : o1.id.compareTo(o2.id);
});
// 分数线
int line = candidates.get(t - 1).score;
int cnt = 0; // 输出cnt行
List<Candidate> passedCandidates = new ArrayList<>();
for(Candidate candidate : candidates) {
if(candidate.score >= line) {
passedCandidates.add(candidate);
cnt++;
}
}
System.out.println(line + " " + cnt);
passedCandidates.forEach(e -> System.out.println(e.id + " " + e.score));
}
}
class Candidate {
Integer id;
Integer score;
public Candidate(Integer id, Integer score) {
this.id = id;
this.score = score;
}
}


