L1-088 静静的推荐
天梯赛结束后,某企业的人力资源部希望组委会能推荐一批优秀的学生,这个整理推荐名单的任务就由静静姐负责。企业接受推荐的流程是这样的:
- 只考虑得分不低于 175 分的学生;
- 一共接受 K 批次的推荐名单;
- 同一批推荐名单上的学生的成绩原则上应严格递增;
- 如果有的学生天梯赛成绩虽然与前一个人相同,但其参加过 PAT 考试,且成绩达到了该企业的面试分数线,则也可以接受。
给定全体参赛学生的成绩和他们的 PAT 考试成绩,请你帮静静姐算一算,她最多能向企业推荐多少学生?
输入格式:
输入第一行给出 3 个正整数:N(≤105)为参赛学生人数,K(≤5×103)为企业接受的推荐批次,S(≤100)为该企业的 PAT 面试分数线。
随后 N 行,每行给出两个分数,依次为一位学生的天梯赛分数(最高分 290)和 PAT 分数(最高分 100)。
输出格式:
在一行中输出静静姐最多能向企业推荐的学生人数。
输入样例:
tex
10 2 90
203 0
169 91
175 88
175 0
175 90
189 0
189 0
189 95
189 89
256 100
10 2 90
203 0
169 91
175 88
175 0
175 90
189 0
189 0
189 95
189 89
256 100
输出样例:
tex
8
8
样例解释:
第一批可以选择 175、189、203、256 这四个分数的学生各一名,此外 175 分 PAT 分数达到 90 分的学生和 189 分 PAT 分数达到 95 分的学生可以额外进入名单。第二批就只剩下 175、189 两个分数的学生各一名可以进入名单了。最终一共 8 人进入推荐名单。
Solution:
java
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.StreamTokenizer;
import java.util.ArrayList;
import java.util.List;
public class Main {
static StreamTokenizer in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
static int nextInt() throws IOException {
in.nextToken();
return (int) in.nval;
}
public static void main(String[] args) throws IOException {
int N = nextInt();
int K = nextInt();
int S = nextInt();
List<Student> list = new ArrayList<>();
for (int i = 0; i < N; i++) {
int gplt = nextInt();
int pat = nextInt();
if (gplt >= 175) list.add(new Student(gplt, pat));
}
list.sort(null);
int cnt = 0;
for (int i = 0; i < K; i++) {
int temp = 101;
for (int j = list.size() - 1; j >= 0; j--) {
Student student = list.get(j);
if (temp != student.gplt) {
cnt++;
temp = student.gplt;
list.remove(j);
} else if (student.pat >= S) {
cnt++;
list.remove(j);
}
}
}
System.out.println(cnt);
}
}
class Student implements Comparable<Student> {
int gplt;
int pat;
public Student(int gplt, int pat) {
this.gplt = gplt;
this.pat = pat;
}
@Override
public int compareTo(Student o) {
int r = o.gplt - this.gplt;
if (r == 0) r = o.pat - this.pat;
return r;
}
}
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.StreamTokenizer;
import java.util.ArrayList;
import java.util.List;
public class Main {
static StreamTokenizer in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
static int nextInt() throws IOException {
in.nextToken();
return (int) in.nval;
}
public static void main(String[] args) throws IOException {
int N = nextInt();
int K = nextInt();
int S = nextInt();
List<Student> list = new ArrayList<>();
for (int i = 0; i < N; i++) {
int gplt = nextInt();
int pat = nextInt();
if (gplt >= 175) list.add(new Student(gplt, pat));
}
list.sort(null);
int cnt = 0;
for (int i = 0; i < K; i++) {
int temp = 101;
for (int j = list.size() - 1; j >= 0; j--) {
Student student = list.get(j);
if (temp != student.gplt) {
cnt++;
temp = student.gplt;
list.remove(j);
} else if (student.pat >= S) {
cnt++;
list.remove(j);
}
}
}
System.out.println(cnt);
}
}
class Student implements Comparable<Student> {
int gplt;
int pat;
public Student(int gplt, int pat) {
this.gplt = gplt;
this.pat = pat;
}
@Override
public int compareTo(Student o) {
int r = o.gplt - this.gplt;
if (r == 0) r = o.pat - this.pat;
return r;
}
}