結果

問題 No.1015 おつりは要らないです
ユーザー ttr
提出日時 2020-05-25 20:47:19
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 353 ms / 2,000 ms
コード長 1,097 bytes
コンパイル時間 384 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 21,936 KB
最終ジャッジ日時 2024-11-18 07:21:00
合計ジャッジ時間 9,203 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 33
権限があれば一括ダウンロードができます

ソースコード

diff #

import heapq
N,X,Y,Z = map(int, input().split())
A = [int(a) for a in input().split()]

h = []
for a in A:
    heapq.heappush(h, -a)

while Z > 0 and h:
    a = heapq.heappop(h)
    if a > -10000:
        Z -= 1
    elif Z >= abs(a)//10000:
        Z -= abs(a)//10000
        a = abs(a)%10000
        if a > 0:
            heapq.heappush(h, -a)
        elif a == 0 and X > 0:
            X -= 1
        elif a == 0 and Y > 0:
            Y -= 1
        elif a == 0:
            Z -= 1
    else:
        a += 10000*Z
        heapq.heappush(h, a)
        Z = 0

while Y > 0 and h:
    a = heapq.heappop(h)
    if a > -5000:
        Y -= 1
    elif Y >= abs(a)//5000:
        Y -= abs(a)//5000
        a = abs(a)%5000
        if a > 0:
            heapq.heappush(h, -a)
        elif a == 0 and X > 0:
            X -= 1
        elif a == 0:
            Y -= 1
    else:
        a += 5000*Y
        heapq.heappush(h, a)
        Y = 0

while X > 0 and h:
    a = -heapq.heappop(h)
    X -= (a-1)//1000+1

if len(h) == 0 and X >= 0 and Y >= 0 and Z >= 0:
    ans = "Yes"
else:
    ans = "No"

print(ans)
0