rueki
BOJ 1417. 국회의원 선거 본문
728x90
반응형
https://www.acmicpc.net/problem/1417
다솜이 투표 수가 다른 사람들 투표수에서 빼서 가져왔을 때 같거나 크면 다른 사람으로 넘어가면 됨
근데 처음에 while 문 사용에 인덱스 설정하려고 별도로 idx 설정했는데 런타임 에러떠서 결국 수정했다...
n = int(input())
dasom = int(input())
if n<=1:
print(0)
else:
others = []
for i in range(n-1):
others.append(int(input()))
others.sort()
cnt = 0
while max(others) >= dasom:
idx = others.index(max(others))
dasom += 1
others[idx] -= 1
cnt+=1
print(cnt)
* 이전 코드
표가 낮은 사람은 지나친다.
다솜이보다 큰 경우는 위와 같이 전개함
n = int(input())
dasom = 0
others = []
for i in range(n):
v = int(input())
if i == 0:
dasom = v
else:
if n != 1:
others.append(v)
dasom_init = dasom
idx = 0
others.sort()
while True:
if len(others) < 1:
print(0)
break
else:
if others[idx] < dasom:
idx += 1
else:
dasom += 1
others[idx] -= 1
if dasom >= others[idx]:
idx += 1
else:
continue
if max(others) < dasom:
print(dasom - dasom_init)
break
728x90
반응형
Comments