A - 朗読の評価 / Evaluation of Reading Aloud Editorial by admin Editorial for printing
swe-2-highExplanation
This problem only requires checking a condition for each student. For student \(i\), append G to the answer string if the voice volume \(A_i\) is at least \(X\) and the reading speed \(B_i\) is at most \(Y\); otherwise append B.
The program first reads \(N\), \(X\), \(Y\), then loops over the students. On each iteration it reads one pair \((A_i, B_i)\), evaluates a >= x && b <= y, and appends the resulting character G or B to the string s. Finally it prints s.
Why it works
The loop processes each student exactly once, in the order \(i = 1, 2, \dots, N\). The character appended on iteration \(i\) is chosen by a condition identical to the problem’s definition of a good reading (\(A_i \geq X\) and \(B_i \leq Y\)), so the \(i\)-th character of s is the correct grade for student \(i\). Hence the printed string of length \(N\) matches the required output.
Complexity
- Time: \(O(N)\) — one constant-time check and one character append per student.
- Space: \(O(N)\) to store the output string. Each input pair is consumed immediately, so extra storage for input is \(O(1)\).
posted:
last update: