A - 料理コンテスト / Cooking Contest Editorial by admin
GPT 5.2 HighOverview
This problem asks you to compute each participant’s “skill value” \(H_i + S_i\) and find the participant number whose value is the maximum (\(D_i\) is ignored).
Analysis
- The total score is \(H_i + S_i + D_i\), but what Aoki wants to see is the pure skill excluding the bonus, so the value to compare is the skill value \(H_i + S_i\).
\(D_i\) is given as input, but it is irrelevant to determining the winner in this problem. - All we need to do is “find the person with the maximum \(H_i + S_i\)”, so it suffices to look at each person once and update the maximum.
- A straightforward approach of “storing all skill values in an array and finding the maximum at the end” also works, but there’s no need to store them in an array — we can update the maximum while reading input, saving memory as well (since \(N \le 2\times 10^5\), either approach is fast enough, but the latter is more concise and safe).
- It is guaranteed that exactly one participant has the maximum, so there is no need to handle ties (multiple people sharing the maximum).
Example:
With 3 participants:
1: \((H,S,D)=(10,20,100)\) → skill value \(30\)
2: \((5,40,0)\) → skill value \(45\)
3: \((30,10,1000)\) → skill value \(40\)
The maximum is \(45\) for participant 2, so the answer is 2 (even though \(D\) is large, it doesn’t matter).
Algorithm
- Initialize
best_score(the maximum skill value so far) to \(-1\). - Prepare
best_idx(the participant number at that point). - For \(i=1\) to \(N\), read the input in order and compute the skill value
score = h + s. - If
score > best_score, updatebest_scoreandbest_idx. - Output
best_idxat the end.
Complexity
- Time complexity: \(O(N)\) (just looking at each person once)
- Space complexity: \(O(1)\) (only storing the maximum value and the index)
Implementation Notes
Participant numbers are 1-indexed as stated in the problem, so the loop should be
for i in range(1, N + 1):.Since there can be up to \(2\times 10^5\) lines of input, using
sys.stdin.readlinein Python ensures stable and fast reading.\(H_i, S_i\) are at most \(10^9\), but their sum is at most \(2\times 10^9\), which Python’s
intcan handle safely.Source Code
import sys
def main():
input = sys.stdin.readline
N = int(input())
best_score = -1
best_idx = -1
for i in range(1, N + 1):
h, s, d = map(int, input().split())
score = h + s
if score > best_score:
best_score = score
best_idx = i
print(best_idx)
if __name__ == "__main__":
main()
This editorial was generated by gpt-5.2-high.