practivceAlgorithm/백준

[백준][Python] 16206 롤케이크

findTheValue 2021. 8. 16. 00:12

나눠 떨어지는 경우와 아닌경우를 나눠 카운팅해주면 된다.

 

import sys
input = sys.stdin.readline

N, M = map(int, input().split())
cakes = list(map(int, input().split()))
cakes.sort(key=lambda x: (x%10,x))
cake_cnt = 0
for cake in cakes:
    cnt = cake//10
    if not cake%10:
        if cnt-1 <= M:
            cake_cnt += cnt
            M -= cnt -1
        else:
            cake_cnt += M
            M -= M
    else:
        if cnt <= M:
            cake_cnt += cnt
            M -= cnt
        else:
            cake_cnt += M
            M -= M
print(cake_cnt)