A - 合格者数 / Number of Successful Applicants 解説 by admin
Claude 4.5 OpusOverview
Given the test scores of \(N\) students, this problem asks you to count the number of students who scored \(K\) points or more (passing students).
Analysis
This problem is very simple and can be solved once you realize the following:
- Key insight: For each student, determine “whether their score is \(K\) points or more” and count the number of students who satisfy this condition
- A naive approach is sufficient: In this problem, \(N \leq 2 \times 10^5\), and we only need to check each student once, so a simple loop is fast enough
- No complex algorithms needed: Sorting or binary search are not necessary; linear search is sufficient
Concrete Example
For example, with \(N = 5\), \(K = 60\), and scores \([45, 60, 72, 58, 80]\): - Student 1: 45 points → Fail (\(45 < 60\)) - Student 2: 60 points → Pass (\(60 \geq 60\)) - Student 3: 72 points → Pass (\(72 \geq 60\)) - Student 4: 58 points → Fail (\(58 < 60\)) - Student 5: 80 points → Pass (\(80 \geq 60\))
Therefore, the number of passing students is 3.
Algorithm
- Read \(N\) and \(K\) from input
- Read the score list \(S\) for \(N\) students
- For each element in list \(S\), count 1 if it is \(K\) or more, otherwise count 0
- Output the total (= number of passing students)
In Python, you can write this concisely by combining a generator expression with the sum() function:
sum(1 for s in S if s >= K)
This means “for each element \(s\) in \(S\), generate 1 if \(s \geq K\), and calculate the sum of these values.”
Complexity
- Time complexity: \(O(N)\)
- Because we check each student’s score exactly once
- Space complexity: \(O(N)\)
- Because we store the score list \(S\)
Implementation Notes
Be careful with comparison operators: The problem states that “\(K\) points or more” is the passing condition, so use
>=(greater than or equal to). Don’t confuse it with>(strictly greater than)Convenient Python idiom:
sum(1 for s in S if s >= K)is a standard idiom for counting elements in a list that satisfy a condition.len([s for s in S if s >= K])produces the same result, but the generator expression is more memory-efficientSource Code
N, K = map(int, input().split())
S = list(map(int, input().split()))
print(sum(1 for s in S if s >= K))
This editorial was generated by claude4.5opus.
投稿日時:
最終更新: