A - モニタリングの最高値 / Monitoring Peak 解説 by admin
gpt-6-astra-mediumOverview
This problem asks us to examine each digit in the string \(S\) and output the maximum value.
Analysis
We want to find the maximum value among the recorded load levels. Therefore, we can find it by checking the load level of each day one by one.
For example, if \(S =\) 30752, the load levels are \(3, 0, 7, 5, 2\), so the answer is \(7\).
For this problem, a naive approach of checking every character is sufficient. Since \(N \leq 100\), there is no need to worry about exceeding the time limit.
However, rather than converting the entire string into an integer, it is important to convert each character individually into an integer and find the maximum among them.
Algorithm
- Read the number of days \(N\) and the string \(S\).
- Convert each character of \(S\) into an integer.
- Find the maximum value using Python’s
maxfunction and output it.
The following part of the code converts each character into an integer and computes the maximum value:
max(int(c) for c in s)
for c in s extracts each character in order, and int(c) converts it into an integer. Since max inspects all of these values, we will certainly obtain the highest load level.
Complexity
- Time complexity: \(O(N)\)
Each character of the string is inspected once. - Space complexity: \(O(N)\)
Required to store the input string. The additional space used to compute the maximum value is \(O(1)\).
Implementation Notes
int(c) for c in sis a generator expression. It passes values tomaxone by one without creating a list of integers, which minimizes additional space.Since \(N \geq 1\), the string is not empty, so
maxwill always successfully find the maximum value.Although \(N\) is read, it is not used in subsequent calculations because the string can be iterated over directly.
Source Code
# 問題文から独立に実装
n = int(input())
s = input().strip()
print(max(int(c) for c in s))
This editorial was generated by gpt-6-astra-medium.