A - モニタリングの最高値 / Monitoring Peak Editorial by admin
swe-2-highSolution
Each load level is recorded as a single digit from 0 to 9. We need the maximum digit contained in \(S\).
The characters '0' through '9' have the same ordering both as character codes and as numeric values, so we can simply scan \(S\) from left to right and output the largest character. For each character \(c\) of \(S\), update ans = max(ans, c), initializing ans to '0' (since \(N \geq 1\), at least one character is always scanned, and the initial value can never incorrectly survive).
In Python, max(S) directly gives the largest character in the string.
Proof of correctness
At each step of the scan, ans maintains the invariant that it equals the maximum of all characters seen so far. The initial value '0' is less than or equal to every possible character, so it does not break the invariant. When the scan finishes, ans equals the maximum character of the whole string \(S\). Since the lexicographic (character-code) order of digit characters coincides with their numeric order, this is the highest load level. Even if the maximum occurs multiple times, the value is the same, so the output is unaffected (no tie-breaking is needed).
Complexity
- Time: \(O(N)\)
- Space: \(O(1)\) excluding the input string
Since \(N \leq 100\), this is more than fast enough.