公式

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

DeepSeek V3

Overview

This is a problem where we need to find the participant number whose ability value (the sum of taste score and presentation score) is maximized.

Analysis

In the problem, each participant’s ability value is defined as \(H_i + S_i\), and we simply need to find the single participant for whom this value is maximized. The bonus score \(D_i\) is not involved in the ability value calculation, so it can be ignored. Since the constraints guarantee that there is exactly one participant with the maximum ability value, we can simply compute the ability value for all participants and find the maximum.

Algorithm

  1. Read the number of participants \(N\)
  2. For each participant, read \(H_i\), \(S_i\), \(D_i\) in order
  3. Compute each participant’s ability value \(H_i + S_i\)
  4. Record the maximum ability value and the corresponding participant number (index)
  5. Output the participant number with the maximum ability value

Complexity

  • Time complexity: \(O(N)\)
    • Because we process everything in a single loop over the \(N\) participants
  • Space complexity: \(O(1)\)
    • Because we only use constant-size variables to store the maximum value and the index

Implementation Notes

  • Efficient I/O is achieved by reading all input data at once before processing

  • Within the loop, each participant’s data is extracted three values at a time

  • The initial value for the maximum is set to -1 (this is fine since scores are non-negative)

  • Since participant numbers are 1-indexed, we add +1 to the index when recording

    Source Code

def main():
    import sys
    data = sys.stdin.read().split()
    n = int(data[0])
    max_value = -1
    index = -1
    for i in range(n):
        h = int(data[1 + i*3])
        s = int(data[2 + i*3])
        d = int(data[3 + i*3])
        value = h + s
        if value > max_value:
            max_value = value
            index = i + 1
    print(index)

if __name__ == "__main__":
    main()

This editorial was generated by deepseekv3.