[백준/파이썬] 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”. …를 만족하도록 로직을 구성하는 것입니다.

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

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



이런 주제는 어떠신가요?

비슷한 난이도와 유형의 문제를 이어서 보면 풀이 감각을 더 빠르게 잡기 좋습니다.

댓글남기기