結果

問題 No.1015 おつりは要らないです
ユーザー kurimupy
提出日時 2020-06-12 23:33:49
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,514 bytes
コンパイル時間 243 ms
コンパイル使用メモリ 82,560 KB
実行使用メモリ 97,784 KB
最終ジャッジ日時 2024-06-24 06:05:01
合計ジャッジ時間 5,498 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 14 WA * 19
権限があれば一括ダウンロードができます

ソースコード

diff #

# problem 3
import math
import heapq
N, X, Y, Z = map(int, input().split())

A = list(map(int, input().split()))

B = []
for num in A:
    B.append(-num-1)
heapq.heapify(B)

flag = True
# 10000円処理のケース

while flag and B:
    x = heapq.heappop(B)*(-1)
    if x < 10000:
        flag = False
        heapq.heappush(B, -x)
        continue

    elif x >= 10000:
        u, v = divmod(x, 10000)
        if u > Z:
            Z -= u
            heapq.heappush(B, -v)
            continue
        elif u <= Z:
            x -= u*10000
            Z=0
            heapq.heappush(B, -x)
            flag = False
if not B:
    print("Yes")
    exit()


flag = True
# 5000円のケース
while flag and B:
    x = heapq.heappop(B)*(-1)
    if x < 5000:
        flag = False
        heapq.heappush(B, -x)
        continue

    elif x >= 5000:
        u, v = divmod(x, 5000)
        if u > Y:
            Y -= u
            heapq.heappush(B, -v)
            continue
        elif u <= Y:
            x -= u*5000
            Y=0
            heapq.heappush(B, -x)
            flag = False
if not B:
    print("Yes")
    exit()

# 1000円の場合
flag = True
judge = True
Left=Y+Z

while B and flag:
    x = heapq.heappop(B)*(-1)
    if Left > 0:
        Left -= 1
        continue
    else:
        u = math.ceil(x/1000)
        if X >= u:
            X -= u
            continue
        else:
            flag = False
            judge = False
            continue
if judge:
    print("Yes")
else:
    print("No")
0