ylab 2022. 4. 14. 08:14

https://www.acmicpc.net/problem/14916

 

14916번: 거스름돈

첫째 줄에 거스름돈 액수 n(1 ≤ n ≤ 100,000)이 주어진다.

www.acmicpc.net

#전형적인 그리디
#2원짜리와 5원짜리로만 거스름돈을 달라고함
#동전의 갯수가 최소가 되도록 거슬러 주어야함

# ==> 5원 무조건 많이 ㅎㅎ
# 2, 4, 5, 7, 9, 10
# 11, 13, .... 만약 5로 나누었을경우 1과 3일 때에는  
import sys

N = int(sys.stdin.readline())

#그냥 1, 3일때는 계산 X
if N==1 or N==3:
    print(-1)
    
#큰 수 먼저    
elif (N%5)%2==0:
    print((N//5)+(N%5//2))
    #print(count)   
    
else :
    print((N//5)-1+(N%5+5)//2)
    
    #print(count)    

# elif N%5==1 or N%5==3:
#     count=(N//5)-1+(N%5+5)//2

#     print(count)    

#if N !=0 :
#    print(-1)
#else: 
#    print(count)

1.

imports sys

sys.stdin.readline()

테스트 케이스에서 일반적인 그리디와 달리 경우의 수 발생

=> 적고, 주석 혹은 메모하면서 문제풀이