結果

問題 No.1015 おつりは要らないです
ユーザー hayatosum
提出日時 2020-04-10 09:51:16
言語 Java
(openjdk 23)
結果
WA  
実行時間 -
コード長 2,082 bytes
コンパイル時間 2,433 ms
コンパイル使用メモリ 80,288 KB
実行使用メモリ 70,616 KB
最終ジャッジ日時 2024-09-14 17:42:58
合計ジャッジ時間 46,579 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 7 WA * 15 TLE * 11
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {

    public static void main(String args[]) {

        // 入力
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int x = Integer.parseInt(sc.next());
        int y = Integer.parseInt(sc.next());
        int z = Integer.parseInt(sc.next());
        Integer[] a = new Integer[n];
        Arrays.setAll(a, i -> Integer.parseInt(sc.next()));
        sc.close();

        // 主処理
        boolean judge = true;

        for (int price : a) {
            int count = (int) Math.ceil((price + 1) / 1000.0);
            while (0 < count) {
                if (10 <= count) {
                    if (1 <= z) {
                        z--;
                    } else if (2 <= y) {
                        y -= 2;
                    } else if (1 <= y && 5 <= x) {
                        y--;
                        x -= 5;
                    } else if (10 <= x) {
                        x -= 10;
                    } else {
                        judge = false;
                        break;
                    }
                    count -= 10;
                } else if (5 <= count) {
                    if (1 <= y) {
                        y--;
                    } else if (5 <= x) {
                        x -= 5;
                    } else if (1 <= z) {
                        z--;
                    } else {
                        judge = false;
                        break;
                    }
                    count -= 5;
                } else {
                    if (count <= x) {
                        x -= count;
                    } else if (1 <= y) {
                        y--;
                    } else if (1 <= z) {
                        z--;
                    } else {
                        judge = false;
                        break;
                    }
                    count = 0;
                }
            }
        }

        String result = judge ? "Yes" : "No";

        // 出力
        System.out.println(result);
    }
}
0