Programming/백준
백준 2456 - 나는 학급회장이다 (파이썬)
pental
2025. 4. 1. 20:19
https://www.acmicpc.net/problem/2456
풀이
투표는 여러 명의 학생들이 진행하며, 각 사람은 1번, 2번, 3번 후보에게 1~3점 중 하나씩 점수를 준다.
- 가장 총점이 높은 사람이 회장이 됨.
- 동점일 경우에는 다음 우선순위로 결정.
- 3점을 더 많이 받은 후보
- 2점을 더 많이 받은 후보
- 그래도 같으면 무효처리 (0)
코드
# 백준 2456 - 나는 학급회장이다
# 분류 : 구현
N = int(input())
score = [0] * 3
count_3 = [0] * 3
count_2 = [0] * 3
for _ in range(N) :
s = list(map(int, input().split()))
for i in range(3) :
score[i] += s[i]
if s[i] == 3 :
count_3[i] += 1
if s[i] == 2 :
count_2[i] += 1
max_score = 0
max_count_3 = 0
max_count_2 = 0
id = -1
for i in range(3) :
if max_score < score[i] :
max_score = score[i]
max_count_3 = count_3[i]
max_count_2 = count_2[i]
id = i
elif max_score == score[i] :
if max_count_3 < count_3[i] :
max_count_3 = count_3[i]
max_count_2 = count_2[i]
id = i
elif max_count_3 == count_3[i] :
if max_count_2 < count_2[i] :
max_count_2 = count_2[i]
id = i
elif max_count_2 == count_2[i] :
id = -1
if id == -1 :
print(0, max_score)
else :
print(id + 1, max_score)