Official

A - 料理コンテスト / Cooking Contest Editorial by admin

Qwen3-Coder-480B

Overview

Find the number of the participant whose sum of “taste score” and “presentation score” (skill value) is the highest. Bonus scores are unrelated to the skill value.

Analysis

In this problem, we need to compute each participant’s skill value \(H_i + S_i\) and answer the number of the participant who has the maximum value. Since the bonus score \(D_i\) does not affect the skill value, it can be ignored in the calculation.

A straightforward approach would be to store all participants’ skill values in an array and then search for the maximum, but since the number of participants \(N\) can be up to \(2 \times 10^5\), while this wouldn’t be particularly disadvantageous in terms of memory usage, processing sequentially is simpler and faster than reading all input first and then processing it.

For this problem, it is sufficient to compute the skill value on the fly as input is received and determine whether to update the maximum value. This eliminates the need for unnecessary arrays or variables, and also reduces space complexity.

Algorithm

  1. Read the number of participants \(N\).
  2. Initialize the maximum skill value max_score to a very small value (or the first value), and initialize the winner’s number winner appropriately.
  3. For each participant, perform the following:
    • Read \(H_i\), \(S_i\), \(D_i\) from input.
    • Compute the skill value as \(H_i + S_i\).
    • If this skill value is greater than the current maximum, update the maximum and the winner’s number.
  4. Finally, output the winner’s number.

Complexity

  • Time complexity: \(O(N)\) → Because constant-time operations are performed for each participant.
  • Space complexity: \(O(1)\) → Only a fixed number of variables are used, independent of the input size.

Implementation Notes

  • The skill value comparison is performed each time input is received, recording the maximum value and its index.

  • Since numbers are 1-indexed (starting from 1), be careful to output i + 1 if the loop variable i starts from 0.

  • It is safe to initialize max_score to an impossibly small value such as -1.

    Source Code

N = int(input())
max_score = -1
winner = -1

for i in range(N):
    H, S, D = map(int, input().split())
    score = H + S
    if score > max_score:
        max_score = score
        winner = i + 1

print(winner)

This editorial was generated by qwen3-coder-480b.