B - 入団オーディション / Audition for Admission Editorial by admin
gemini-3-flash-thinkingOverview
This is a problem where, given \(N\) candidates, we need to determine whether a person ranks within the top \(K\) among the remaining members after removing those who have withdrawn. Takahashi is candidate number \(1\), and rankings are determined first by higher scores, then by smaller candidate numbers as a tiebreaker.
Analysis
The passing conditions can be summarized as follows: 1. Candidates with higher scores rank higher. 2. If scores are equal, the candidate with the smaller number ranks higher.
Focusing on Takahashi (number \(1\)), when comparing him with any other candidate \(i\) (\(i > 1\)), Takahashi always has the smaller number. Therefore, by the tiebreaker rule, if scores are equal, Takahashi always ranks higher.
In other words, the only candidates who rank above Takahashi are those who satisfy both of the following conditions: - They have not withdrawn. - They have a strictly higher score than Takahashi (\(S_i > S_1\)).
Since Takahashi’s rank is determined by “(number of people ranked above him) + 1”, we count the number of non-withdrawn candidates satisfying \(S_i > S_1\). If this count is at most \(K-1\), then Takahashi ranks within the top \(K\) and passes.
Algorithm
- Read \(N, K, M\) and each candidate’s score \(S_i\) from the input.
- Using the list of withdrawn candidates \(D\), create an array (or set) to determine whether each candidate has withdrawn.
- Using Takahashi’s score \(S_1\) as a reference, count the number of candidates
better_than_takahashisatisfying the following conditions:- The candidate’s number \(i\) is between \(2\) and \(N\) inclusive.
- Candidate \(i\) has not withdrawn.
- \(S_i > S_1\).
- If
better_than_takahashi + 1 <= K, outputYes; otherwise, outputNo.
Complexity
- Time complexity: \(O(N)\)
- Reading the input takes \(O(N)\), marking withdrawn candidates takes \(O(M)\), and comparing scores takes \(O(N)\). Since \(M \le N\), the overall complexity is \(O(N)\), which runs sufficiently fast for the constraint \(N = 2 \times 10^5\).
- Space complexity: \(O(N)\)
- \(O(N)\) memory is used to store the score list and the withdrawal status array.
Implementation Notes
Tiebreaker handling: Since Takahashi has the smallest number (1), there is no need to consider the case where
S[i] == S[1]. The key insight is that we only need to checkS[i] > S[1].Fast input: Since \(N\) can be large, in Python it is efficient to read all input at once using
sys.stdin.read().split()or similar methods.Managing withdrawn candidates: To quickly determine whether a candidate has withdrawn, use a boolean array or a hash set.
Source Code
import sys
def solve():
# Read all input at once and split into tokens for efficient processing
try:
input_data = sys.stdin.read().split()
except EOFError:
return
if not input_data:
return
# N: total number of candidates
# K: number of candidates who will pass
# M: number of candidates who withdrew
n = int(input_data[0])
k = int(input_data[1])
m = int(input_data[2])
# Candidate 1 is Takahashi. His score is S_1.
# Scores are given as S_1, S_2, ..., S_N starting from input_data[3].
s1 = int(input_data[3])
# Mark which candidates have withdrawn using a boolean array.
# Candidate IDs are 1-indexed (from 1 to N).
# M can be 0, in which case the withdrawn list will remain all False.
is_withdrawn = [False] * (n + 1)
if m > 0:
# Withdrawn candidate IDs D_1, ..., D_M follow the N scores in the input.
for i in range(m):
d_id = int(input_data[3 + n + i])
is_withdrawn[d_id] = True
# Count how many remaining candidates are ranked strictly higher than Takahashi.
# According to the rules:
# 1. Higher score is better.
# 2. If scores are equal, the smaller candidate ID is better.
# Since Takahashi is candidate 1, any other candidate i (where i > 1)
# can only be ranked higher than Takahashi if their score S_i is strictly greater than S_1.
better_than_takahashi = 0
for i in range(2, n + 1):
if not is_withdrawn[i]:
# The score S_i for candidate i is located at input_data[3 + i - 1]
si = int(input_data[3 + i - 1])
if si > s1:
better_than_takahashi += 1
# Takahashi's rank among the remaining candidates is (better_than_takahashi + 1).
# He passes if his rank is less than or equal to K.
if better_than_takahashi + 1 <= k:
print("Yes")
else:
print("No")
if __name__ == '__main__':
solve()
This editorial was generated by gemini-3-flash-thinking.
posted:
last update: