結果

問題 No.1015 おつりは要らないです
ユーザー kurimupykurimupy
提出日時 2020-06-12 23:53:21
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 214 ms / 2,000 ms
コード長 1,700 bytes
コンパイル時間 173 ms
コンパイル使用メモリ 82,304 KB
実行使用メモリ 97,280 KB
最終ジャッジ日時 2024-04-29 06:16:40
合計ジャッジ時間 6,110 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 34 ms
53,120 KB
testcase_01 AC 31 ms
52,480 KB
testcase_02 AC 33 ms
52,864 KB
testcase_03 AC 32 ms
53,376 KB
testcase_04 AC 32 ms
52,480 KB
testcase_05 AC 33 ms
52,480 KB
testcase_06 AC 32 ms
52,608 KB
testcase_07 AC 34 ms
52,736 KB
testcase_08 AC 33 ms
53,376 KB
testcase_09 AC 35 ms
52,864 KB
testcase_10 AC 186 ms
97,228 KB
testcase_11 AC 194 ms
96,512 KB
testcase_12 AC 184 ms
96,920 KB
testcase_13 AC 188 ms
96,576 KB
testcase_14 AC 203 ms
96,980 KB
testcase_15 AC 191 ms
96,384 KB
testcase_16 AC 191 ms
97,280 KB
testcase_17 AC 199 ms
96,768 KB
testcase_18 AC 192 ms
96,668 KB
testcase_19 AC 196 ms
96,384 KB
testcase_20 AC 200 ms
96,828 KB
testcase_21 AC 197 ms
96,256 KB
testcase_22 AC 201 ms
96,384 KB
testcase_23 AC 196 ms
96,128 KB
testcase_24 AC 210 ms
97,024 KB
testcase_25 AC 198 ms
96,620 KB
testcase_26 AC 196 ms
96,256 KB
testcase_27 AC 201 ms
96,896 KB
testcase_28 AC 214 ms
96,372 KB
testcase_29 AC 196 ms
96,256 KB
testcase_30 AC 37 ms
52,608 KB
testcase_31 AC 99 ms
94,720 KB
testcase_32 AC 96 ms
94,636 KB
testcase_33 AC 104 ms
97,024 KB
testcase_34 AC 35 ms
52,608 KB
testcase_35 AC 33 ms
52,936 KB
testcase_36 AC 38 ms
52,864 KB
権限があれば一括ダウンロードができます

ソースコード

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:
        if Z == 0:
            heapq.heappush(B, -x)
            flag = False
            continue
        elif Z > 0:
            Z -= 1
            continue

    elif x >= 10000:
        u, v = divmod(x, 10000)
        if u < Z:
            Z -= u
            heapq.heappush(B, -v)
            continue
        elif u >= Z:
            x -= Z*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:
        if Y == 0:
            heapq.heappush(B, -x)
            flag = False
            continue
        elif Y > 0:
            Y -= 1
            continue
    elif x >= 5000:
        u, v = divmod(x, 5000)
        if u < Y:
            Y -= u
            heapq.heappush(B, -v)
            continue
        elif u >= Y:
            x -= Y*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