#26 백준 2839번 파이썬
우보만리
- 몫과 나머지를 한번에 계산해주는
divmod
함수를 사용했다. - 가장 효율적으로 설탕을 담기 위해서는 5kg 봉지를 많이 사용하는 것이 좋다는 점이 해결 포인트.
- 5kg 봉투를 가장 많이 사용한 경우에서 시작해 3kg 봉투의 사용을 늘리는 과정을 for문으로 구현함.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
T = int(input()) | |
B5, rem = divmod(T,5) | |
if rem == 0: | |
print(B5) | |
else: | |
for i in range(B5,-1,-1): | |
B3, rem = divmod(T - i*5, 3) | |
if rem == 0: | |
print(i + B3) | |
break | |
if i == 0: | |
print(-1) | |
## Memory : 123316 KB | |
## Runtime : 112 ms |