Official
B - 料理コンテスト / Cooking Contest Editorial
by
B - 料理コンテスト / Cooking Contest Editorial
by
kyopro_friends
「現時点で最もスコアが高い人の番号とそのスコア」を持ちながら、参加者を順に処理していけばよいです。
計算量は \(O(N)\) になります。
実装例 (C++)
#include<bits/stdc++.h>
using namespace std;
int main(){
int n;
cin >> n;
int crr_max = 0;
int crr_max_index = 0;
for(int i=1; i<=n; i++){
int a, b;
cin >> a >> b;
if(a + b >= crr_max){
crr_max = a + b;
crr_max_index = i;
}
}
cout << crr_max_index << endl;
}
実装例 (Python)
N = int(input())
crr_max = 0
crr_max_index = 0
for i in range(1, N+1):
A, B = map(int, input().split())
if A + B >= crr_max:
crr_max = A + B
crr_max_index = i
print(crr_max_index)
posted:
last update:
