Official

A - 合格基準 / Passing Criteria Editorial by admin

Claude 4.5 Opus

Overview

This problem asks you to determine whether each student’s score is within an acceptable range from a reference score, and count the number of passing students.

Analysis

In this problem, we can see that we simply need to check each student individually to see if they “satisfy the passing condition.”

The passing condition is \(|A_i - S| \leq T\). This means “the absolute difference between the student’s score \(A_i\) and the reference score \(S\) is at most \(T\).”

Understanding with a Concrete Example

For example, if the reference score is \(S = 70\) and the allowed difference is \(T = 5\): - Score of \(68\) points → \(|68 - 70| = 2 \leq 5\)Pass - Score of \(75\) points → \(|75 - 70| = 5 \leq 5\)Pass - Score of \(64\) points → \(|64 - 70| = 6 > 5\)Fail

In other words, students pass if their score falls within the range from \(65\) to \(75\) points.

Key Points of This Problem

  • It is sufficient to check each student one by one
  • No special algorithm is needed; it can be solved with a simple loop
  • Given the constraint \(N \leq 2 \times 10^5\), an \(O(N)\) solution is fast enough

Algorithm

  1. Read the input (\(N, S, T\) and the list of student scores \(A\))
  2. Prepare a variable to count the number of passing students
  3. For each student’s score \(A_i\), check whether \(|A_i - S| \leq T\) is satisfied
  4. If the condition is satisfied, increment the count by 1
  5. Output the final count

In Python, you can write this concisely by combining a generator expression with the sum function:

count = sum(1 for a in A if abs(a - S) <= T)

This adds 1 for each element that satisfies the condition, ultimately giving the count of elements that meet the condition.

Complexity

  • Time complexity: \(O(N)\)
    • Because we perform one check for each of the \(N\) students
  • Space complexity: \(O(N)\)
    • Because we store \(N\) elements in the list of student scores

Implementation Tips

  • Using the abs() function makes calculating absolute values concise

  • The condition abs(a - S) <= T is equivalent to S - T <= a <= S + T, but using absolute value directly expresses the problem’s condition and is less error-prone

  • Using list comprehensions or generator expressions allows you to write the counting process in a single line

    Source Code

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

count = sum(1 for a in A if abs(a - S) <= T)
print(count)

This editorial was generated by claude4.5opus.

posted:
last update: