A - 合格者数の集計 / Counting the Number of Successful Applicants Editorial by admin
Qwen3-Coder-480BOverview
This is a problem where you need to count the total number of students who scored at least \(K\) points (the passing threshold) among students belonging to multiple classes.
Analysis
This problem simply requires checking every student’s score and determining whether it is at least \(K\) points. There are no particularly difficult conditions or constraints.
For example, consider the following sample input:
2 70
3 60 80 90
2 50 75
- Class 1 has 3 students with scores of 60, 80, and 90 points respectively.
- Class 2 has 2 students with scores of 50 and 75 points respectively.
- Since the passing threshold is \(K = 70\) points:
- In Class 1, 2 students pass with scores of 80 and 90.
- In Class 2, only 1 student passes with a score of 75.
- Therefore, a total of \(2 + 1 = 3\) students pass.
In this way, the answer can be obtained by simply examining each student’s score in each class one by one and incrementing a counter whenever the score is at least \(K\).
Also, looking at the constraints, the total number of students is at most \(10^6\), so even checking all of them once is more than fast enough (there are no issues in terms of time complexity).
Algorithm
- First, read \(N\) (the number of classes) and \(K\) (the passing threshold).
- For each class, perform the following:
- Read the number of students \(A_i\) in that class, along with each student’s score \(B_{i,1}, B_{i,2}, \ldots, B_{i,A_i}\).
- Check whether each score is at least \(K\), and if so, increment the counter.
- Finally, output the value of the counter.
Complexity
- Time complexity: \(O(\sum_{i=1}^{N} A_i)\) (= the sum of the number of students across all classes)
- Space complexity: \(O(1)\) (constant memory excluding input)
Implementation Notes
Each line of input can be easily converted to a list of integers using
map(int, input().split())or similar.Note that the first value on each class’s line is the number of students \(A_i\), followed by the scores.
Make sure to initialize the counter variable for passing students outside the loop.
Source Code
N, K = map(int, input().split())
count = 0
for _ in range(N):
data = list(map(int, input().split()))
A = data[0]
scores = data[1:]
for score in scores:
if score >= K:
count += 1
print(count)
This editorial was generated by qwen3-coder-480b.
posted:
last update: