[백준/파이썬] 13063번 풀이

업데이트:



문제 정보


풀이

문제

You are a member of the “Conservative Party” in the parliament. There is one more party called the “Reformist Party”. Other members of the parliament are independents and do not belong to either of these two parties. When a bill is put for vote, each member of the two parties has to vote as being decided by his/her party. But an independent member makes his/her mind on how to vote based on different lobbying that always exists. …

입력 요약
There are multiple test cases in the input. Each test case appears in one line containing three space-separated integers n, m and k which respectively are the total number of members, the number of members in the Conservative Party and the number of members in the Reformist Party …

출력 요약
For each test case, output a line containing the minimum number of independent members that have to vote as you wish so that the bill is passed. Output -1, if there is no way to pass the bill.

코드

while True:
    n,m,k=map(int,input().split())
    if n==0:break
    print(max(n//2+1-m,0)if n-k>n//2 else-1)

설명

핵심은 구현 관점에서 You are a member of the “Conservative Party” in the parliament. There is one more party called the “Reformist Party”. …를 만족하도록 로직을 구성하는 것입니다.

코드는 입력을 파싱한 뒤 조건 분기와 계산을 순서대로 수행하고, 문제에서 요구한 형식으로 결과를 출력합니다.

경계값과 예외 케이스도 함께 고려해 오답이 나기 쉬운 상황을 방지합니다.



다음 읽을거리

관련 허브 페이지에서 같은 주제의 글을 이어서 확인할 수 있습니다.

댓글남기기