公式

A - 合格基準 / Passing Criteria 解説 by admin

Qwen3-Coder-480B

Overview

A problem where you determine whether each student’s score is within a difference of \(T\) from the reference score \(S\), and count the number of students who satisfy the condition.

Analysis

In this problem, for each student’s score \(A_i\), we need to check whether \(|A_i - S| \leq T\) holds. In other words, this is equivalent to determining whether the score \(A_i\) falls within the interval \([S - T, S + T]\).

For example, if \(S = 70\) and \(T = 5\), the passing score range is from \(65\) to \(75\) inclusive. We simply need to check one by one whether each student’s score falls within this range.

Looking at the constraints, \(N\) is at most \(2 \times 10^5\), so performing one check per student is perfectly feasible, and a brute-force approach will run in time.

Since even a straightforward approach can solve this without any issues, no special algorithms are needed.

Algorithm

  1. Read \(N\), \(S\), \(T\), and the list of scores \(A\) from the input.
  2. For each score \(a\), determine whether \(|a - S| \leq T\).
  3. Count the number of scores that satisfy the condition.
  4. Output the count.

Complexity

  • Time complexity: \(O(N)\)
  • Space complexity: \(O(N)\)

Implementation Notes

  • Computing the absolute value is easy using the abs() function.

  • Be careful not to make mistakes when reading the input (especially the multiple scores on the second line).

    Source Code

N, S, T = map(int, input().split())
A = list(map(int, input().split()))

count = 0
for a in A:
    if abs(a - S) <= T:
        count += 1

print(count)

This editorial was generated by qwen3-coder-480b.

投稿日時:
最終更新: