結果

問題 No.1736 Princess vs. Dragoness
ユーザー gew1fw
提出日時 2025-06-12 19:57:36
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 2,437 bytes
コンパイル時間 301 ms
コンパイル使用メモリ 82,048 KB
実行使用メモリ 76,544 KB
最終ジャッジ日時 2025-06-12 20:00:04
合計ジャッジ時間 5,397 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 26 WA * 7
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

def main():
    N, A, B, X, Y = map(int, sys.stdin.readline().split())
    H = list(map(int, sys.stdin.readline().split()))
    
    for b in range(0, B+1):
        # Case 1: Apply b B spells first, then compute A
        current_H = H.copy()
        Y_total = Y * b
        remaining = Y_total
        for i in range(N):
            if current_H[i] <= 0:
                continue
            if remaining <= 0:
                break
            D = min(current_H[i], remaining)
            current_H[i] -= D
            remaining -= D
        # Compute required A
        total_a = 0
        feasible = True
        for h in current_H:
            if h > 0:
                total_a += (h + X - 1) // X
                if total_a > A:
                    feasible = False
                    break
        if feasible:
            print("Yes")
            return
        
        # Case 2: Apply all A first, then b B spells
        current_H_case2 = H.copy()
        a_used = 0
        for i in range(N):
            if a_used >= A:
                break
            # Apply A to current monster as much as possible
            if current_H_case2[i] <= 0:
                continue
            # Maximum possible A spells for this monster
            max_a = (current_H_case2[i] + X - 1) // X  # Ceiling division
            apply_a = min(max_a, A - a_used)
            current_H_case2[i] -= apply_a * X
            a_used += apply_a
            if current_H_case2[i] <= 0:
                continue
            # Apply one more if possible
            if a_used < A:
                apply_a = 1
                current_H_case2[i] -= apply_a * X
                a_used += apply_a
                if current_H_case2[i] < 0:
                    current_H_case2[i] = 0
        
        # Now apply b B spells
        Y_total = Y * b
        remaining = Y_total
        for i in range(N):
            if current_H_case2[i] <= 0:
                continue
            if remaining <= 0:
                break
            D = min(current_H_case2[i], remaining)
            current_H_case2[i] -= D
            remaining -= D
        
        # Check if all are zero or below
        all_zero = True
        for h in current_H_case2:
            if h > 0:
                all_zero = False
                break
        if all_zero:
            print("Yes")
            return
    
    print("No")

if __name__ == "__main__":
    main()
0