Official

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

Claude 4.6 Opus (Thinking)

Overview

For each of the \(N\) participants, calculate the ability value \(H_i + S_i\), which is the sum of their “taste score \(H_i\)” and “presentation score \(S_i\)”, and find the participant number that maximizes this value.

Analysis

  • Each participant is given three values \(H_i\), \(S_i\), and \(D_i\), but the bonus score \(D_i\) is completely irrelevant to the calculation of the ability value. This corresponds to the problem statement’s description of wanting to “evaluate pure cooking skill excluding the influence of special ingredients.”
  • In other words, the key insight is that \(D_i\) is a value that can be discarded, and we only need to look at \(H_i + S_i\) for each participant.
  • This problem reduces to the fundamental problem of “finding the index with the maximum value among \(N\) values.”
  • Since \(N\) is at most \(2 \times 10^5\), an \(O(N)\) approach that examines each participant once is more than sufficient. No special algorithm is needed.

Algorithm

  1. Prepare a variable best_val to hold “the maximum ability value so far” and a variable best_idx to hold “the corresponding participant number.”
  2. For each participant \(i = 1, 2, \dots, N\) in order, do the following:
    • Read \(H_i, S_i, D_i\) from the input.
    • Calculate the ability value \(\text{val} = H_i + S_i\) (\(D_i\) is not used).
    • If \(\text{val} > \text{best\_val}\), update best_val to \(\text{val}\) and best_idx to \(i\).
  3. Output the final best_idx.

Concrete example: Suppose \(N = 3\) and the following input is given.

Participant \(H_i\) \(S_i\) \(D_i\) Ability value \(H_i + S_i\)
1 100 50 200 150
2 80 90 10 170
3 60 70 300 130

Participant 1 has the highest total score \(100+50+200=350\), but their ability value is \(150\). The maximum ability value belongs to participant 2 with \(170\), so the answer is 2. The key point is not to be misled by \(D_i\).

Complexity

  • Time complexity: \(O(N)\) — just a single pass through all participants
  • Space complexity: \(O(1)\) — only variables to hold the maximum value and its index are used (no need to store all data in an array)

Implementation Notes

  • The initial value of best_val is set to \(-1\), but since the constraints guarantee \(H_i \geq 0, S_i \geq 0\), the ability value is always at least \(0\), so it will always be updated by the first participant, causing no issues.

  • Note that participant numbers are 1-indexed (starting from 1). By using for i in range(1, N+1), the loop variable can be used directly as the participant number.

  • \(D_i\) is read from the input but is not used in the calculation. Just be careful to read it correctly according to the input format.

    Source Code

N = int(input())
best_idx = -1
best_val = -1
for i in range(1, N + 1):
    H, S, D = map(int, input().split())
    val = H + S
    if val > best_val:
        best_val = val
        best_idx = i
print(best_idx)

This editorial was generated by claude4.6opus-thinking.