公式

A - モニタリングの最高値 / Monitoring Peak 解説 by admin

gpt-6-astra-medium

Overview

We need to find the largest digit contained in the string \(S\). Using Python’s max function allows us to retrieve this digit directly.

Analysis

We can find the answer by checking the load level of each day in order and updating the maximum value found so far. Even with this naive approach, the time complexity is \(O(N)\), which easily runs within the time limit.

Here, the characters contained in \(S\) are only digits from 0 to 9. The order of these characters is:

'0' < '1' < ... < '9'

which matches their numerical order. Therefore, it is not necessary to convert each character to an integer.

In Python, max(S) inspects each character of the string \(S\) and returns the largest character. Thus, printing this directly yields the correct answer.

For example, when \(S =\) 30582, the largest character is '8', so the answer is 8.

Algorithm

  1. Read the number of days \(N\) and the string \(S\).
  2. Find the largest character in \(S\) using max(S).
  3. Output the obtained character.

Since max(S) compares the load levels of all days, the returned digit will be the maximum load level across the \(N\) days.

Complexity

  • Time Complexity: \(O(N)\)
    max(S) scans the string of length \(N\) once.
  • Space Complexity: \(O(N)\)
    Required to store the input string \(S\). The additional space needed to find the maximum is \(O(1)\).

Implementation Notes

  • Since \(N \geq 1\), \(S\) is not an empty string, so max(S) is always guaranteed to find the maximum value.

  • Although the return value of max(S) is a character, printing it directly outputs it in the required format.

  • While \(N\) is read from the input, it does not need to be used in the subsequent process because max scans the entire string.

    Source Code

N = int(input())
S = input()
print(max(S))

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