Official

A - 快適な気温 / Comfortable Temperature Editorial by admin

gpt-5.3-codex

Overview

This problem asks you to check, for each day, whether the temperature \(T_i\) falls within the comfortable range \([L, R]\), and count the number of days that satisfy the condition.
It can be solved by simply checking each day once.

Analysis

The key observation is very simple.

  • Whether a given day is good for going out is determined solely by that day’s temperature \(T_i\)
  • Since there is no relationship between days, we can judge each day independently and sum up the results

In other words, for each \(i\), we check whether
\(L \leq T_i \leq R\)
holds, and if so, increment the count by \(1\).

Concrete Example

For example, if \(L=15, R=25\) and the temperatures are
\([10, 15, 20, 30]\)
then \(15\) and \(20\) fall within the range, so the answer is 2.

Comparison with a Naive Approach

In this problem, “brute force (checking all days)” is already optimal as-is.
Since \(N \le 10^5\), checking each day once (a total of \(N\) times) is fast enough.
Conversely, adding unnecessarily complex operations (such as sorting) only makes the implementation heavier with no benefit.

Algorithm

  1. Read \(N, L, R\) and \(N\) temperature values from input
  2. Iterate through the temperature array from the beginning, and for each \(t\), check whether \(L \le t \le R\)
  3. If true, increment the count
  4. Output the count at the end

In the provided code, steps 2 and 3 are done in a single line:

  • sum(1 for t in temps if l <= t <= r)

This is a way of writing “add 1 for each element that satisfies the condition.”

Complexity

  • Time complexity: \(O(N)\)
  • Space complexity: \(O(N)\) (because the implementation stores the input temperatures in temps)

Implementation Notes

  • In Python, you can write l <= t <= r using chained comparisons, which is very readable.

  • Even when input is large, using sys.stdin.buffer.read() allows for fast reading.

  • Since this problem completes in a single pass, keeping the logic focused on just “check and count” helps reduce mistakes.

    Source Code

import sys

def main():
    data = list(map(int, sys.stdin.buffer.read().split()))
    n, l, r = data[0], data[1], data[2]
    temps = data[3:3 + n]

    count = sum(1 for t in temps if l <= t <= r)
    print(count)

if __name__ == "__main__":
    main()

This editorial was generated by gpt-5.3-codex.

posted:
last update: