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

업데이트:



문제 정보


풀이

문제

Pero has negotiated a Very Good data plan with his internet provider. The provider will let Pero use up X megabytes to surf the internet per month. Each megabyte that he doesn’t spend in that month gets transferred to the next month and can still be spent. Of course, Pero can only spend the megabytes he actually has.

If we know how much megabytes Pero has spent in each of the first N months of using the plan, determine how many megabytes Pero will have available in the N + 1 month of using the plan.

입력 요약
The first line of input contains the integer X (1 ≤ X ≤ 100).

The second line of input contains the integer N ​(1 ≤ N ≤ 100).

Each of the following N lines contains an integer Pi (0 ≤ Pi ​≤ 10 000), the number of megabytes spent in each of the first N months of using the plan. …

출력 요약
The first and only line of output must contain the required value from the task.

코드

x=int(input())
print(sum([x-int(input())for _ in range(int(input()))])+x)

설명

핵심은 구현 관점에서 Pero has negotiated a Very Good data plan with his internet provider. The provider will let Pero use up X megabytes to surf the internet per month. …를 만족하도록 로직을 구성하는 것입니다.

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

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



다음 읽을거리

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

댓글남기기