結果

問題 No.1015 おつりは要らないです
ユーザー ntk3264
提出日時 2020-04-04 14:59:22
言語 Java
(openjdk 23)
結果
WA  
実行時間 -
コード長 2,383 bytes
コンパイル時間 2,415 ms
コンパイル使用メモリ 77,620 KB
実行使用メモリ 50,468 KB
最終ジャッジ日時 2024-07-03 07:20:18
合計ジャッジ時間 19,315 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 17 WA * 16
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.PrintWriter;
import java.util.*;

public class Main {

    Scanner sc = new Scanner(System.in);

    public static void main(String[] args) {
        new Main().run();
    }

    void run() {

        int n = sc.nextInt();
        int x = sc.nextInt();
        int y = sc.nextInt();
        int z = sc.nextInt();

        int[] arr = new int[n];
        for (int i=0; i<n; i++) arr[i] = sc.nextInt();

        Arrays.sort(arr);

        label:
        for (int i=0; i<n; i++) {
            int price = arr[i];
            int div = price / 1000;

            if (div==0) {
                if (x>0) {
                    x--;
                    continue label;
                } else if (y>0) {
                    y--;
                    continue label;
                } else if (z>0) {
                    z--;
                    continue label;
                } else if (z<=0) {
                    System.out.print("No");
                    return;
                }
            } else if (1<=div) {
                if (0<price && price<5000) {
                    y--;
                    continue label;
                } else if (5000<=price) {
                    int tmp = price / 5000;
                    if (x>=div+1) {
                        x -= (div+1);
                    } else {
                        price -= x*1000;
                        x = 0;
                    }
                    if (y>=tmp+1) {
                        y -= (tmp+1);
                        continue label;
                    } else {
                        price -= y*5000;
                        y = 0;
                        if (price<=0) continue label;
                    }
                }
                if (5000<=price) {
                    if (price<10000) {
                        z--;
                        continue label;
                    } else {
                        int tmp = price / 10000;
                        if (z>=tmp+1) {
                            z -= (tmp+1);
                            continue label;
                        } else {
                            System.out.print("No");
//                            System.out.print("here");

                            return;
                        }
                    }
                }
            }

        }

        System.out.print("Yes");


    }

}
0