본문 바로가기
프로그래밍/acmcpc

[1417] 국회의원 선거

by blopz 2025. 8. 11.

일단 다솜이가 지고 있으면 기존에 제일 표 많은 놈에게서 한 표 뺏어온다.

결국 표 제일 많은 놈을 이기면 다솜이가 이기기 때문이다.

import sys

N = int(sys.stdin.readline().strip())
Ms = [int(sys.stdin.readline().strip()) for _ in range(N)]

dasom = Ms[0]
others = sorted(Ms[1:])
try_count = 0

while len(others) and max(others) >= dasom:
    others[-1] = others[-1] - 1
    others.sort()
    
    # max_value = others.pop()
    # for oi in reversed(range(len(others))):
    #     if others[oi] <= max_value - 1:
    #         others.insert(oi + 1, max_value - 1)
    #         break

    #print(others)
    dasom += 1
    try_count += 1
    
print(try_count)

'프로그래밍 > acmcpc' 카테고리의 다른 글

[2346] 풍선 터뜨리기  (0) 2025.08.26
[5545] 최고의 피자  (4) 2025.08.11
[2503] 숫자 야구  (0) 2025.08.11
[2798] 블랙잭  (0) 2025.08.11
[1158] 요세푸스 문제  (2) 2025.08.11