A - 合格ライン / Passing Score Editorial by admin Editorial for printing
GPT 5.2 HighOverview
This problem asks you to look at each student’s score \(A_i\), count the number of students below the passing threshold \(X\), and output that count.
Analysis
All we need to find is “how many students satisfy \(A_i < X\)”, so it suffices to check each score once and increment a counter whenever the condition is met.
For example, if \(X=60\) and the scores are \([55, 60, 70, 10]\), then the scores below \(60\) are \(55\) and \(10\), giving an answer of \(2\).
Although the constraint \(N \le 2 \times 10^5\) is large, simply examining each student once runs in \(O(N)\), which is fast enough. Alternatively, sorting the scores first and then counting is also possible, but it takes \(O(N \log N)\), which is unnecessarily heavy and deviates from the essence of the problem (counting the number of elements satisfying a condition). Simply “compare and count” is the most straightforward approach.
Algorithm
- Read \(N, X\) and the array \(A\) from input.
- Initialize a counter
ansto \(0\). - For each \(a \in A\), if \(a < X\), increment
ansby \(1\). - Output
ans.
In the provided code, sum(1 for a in A if a < X) computes the number of elements satisfying the condition all at once.
Complexity
- Time complexity: \(O(N)\) (each score is compared exactly once)
- Space complexity: \(O(N)\) (to store the score sequence \(A\))
Implementation Notes
Since the input can contain up to \(2 \times 10^5\) elements, using
sys.stdin.read()in Python to read everything at once is faster and safer.The condition is “strictly below the passing threshold”, so the comparison should be \(a < X\) (not \(a \le X\)). Be careful about this distinction.
Source Code
import sys
def main():
data = sys.stdin.read().strip().split()
if not data:
return
N = int(data[0])
X = int(data[1])
A = list(map(int, data[2:2+N]))
ans = sum(1 for a in A if a < X)
print(ans)
if __name__ == "__main__":
main()
This editorial was generated by gpt-5.2-high.
posted:
last update: