Official

A - 朗読の評価 / Evaluation of Reading Aloud Editorial by admin Editorial for printing

gpt-6-astra-medium

Summary

For each student, if their voice volume is at least \(X\) and their reading speed is at most \(Y\), evaluate them as G; otherwise, evaluate them as B. Output the evaluation results in the order they were given in the input.

Analysis

A student’s evaluation depends only on their own \(A_i, B_i\) and the thresholds \(X, Y\), independent of any other students. Therefore, it is sufficient to evaluate each student one by one in the order of input.

The condition to receive a G is satisfying both of the following:

  • Voice volume is at least the threshold: \(A_i \geq X\)
  • Reading speed is at most the threshold: \(B_i \leq Y\)

For example, when \(X = 50, Y = 60\), the evaluations are as follows:

Voice Volume \(A_i\) Reading Speed \(B_i\) Evaluation Reason
\(50\) \(60\) G Satisfies both conditions
\(70\) \(80\) B Reading speed exceeds \(Y\)
\(40\) \(50\) B Voice volume is less than \(X\)

For this problem, naively checking each person once is fast enough to solve it. However, treating the condition as “satisfying either one is sufficient” will result in a Wrong Answer. Also, note that since the conditions are “at least” and “at most”, values equal to the thresholds also satisfy the conditions.

Algorithm

  1. Read \(N, X, Y\), and initialize an empty list res to store the results.
  2. For each student, perform the following in the order of input:
    • Read \(A_i, B_i\).
    • If \(A_i \geq X\) and \(B_i \leq Y\), append G to res.
    • Otherwise, append B to res.
  3. Concatenate the characters in res without separators and output the result.

By evaluating each student according to the problem statement and appending characters in that order, the desired evaluation string is obtained.

Complexity

  • Time complexity: \(O(N)\)
    Each student is evaluated once, and a string of length \(N\) is constructed at the end.
  • Space complexity: \(O(N)\)
    The evaluations for the \(N\) students are stored in a list.

Implementation Details

  • In Python, requiring both conditions to hold is expressed using and.

    
    a >= x and b <= y
    

  • To include the cases where values are equal to the thresholds, use >= and <= instead of > and <.

  • By using print("".join(res)), you can output the string of length \(N\) on a single line without spaces between the evaluations.

    Source Code

# 問題文から独立に実装
n, x, y = map(int, input().split())
res = []
for _ in range(n):
    a, b = map(int, input().split())
    res.append('G' if a >= x and b <= y else 'B')
print("".join(res))

This editorial was generated by gpt-6-astra-medium.

posted:
last update: