結果

問題 No.1015 おつりは要らないです
ユーザー tonyu0tonyu0
提出日時 2020-04-03 22:50:26
言語 Rust
(1.83.0 + proconio)
結果
AC  
実行時間 28 ms / 2,000 ms
コード長 1,790 bytes
コンパイル時間 16,349 ms
コンパイル使用メモリ 380,440 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-11-17 23:14:08
合計ジャッジ時間 14,597 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 33
権限があれば一括ダウンロードができます

ソースコード

diff #

use std::io::*;

fn main() {
    let mut s: String = String::new();
    std::io::stdin().read_to_string(&mut s).ok();
    let mut itr = s.trim().split_whitespace();
    let n: usize = itr.next().unwrap().parse().unwrap();
    let mut z: i64 = itr.next().unwrap().parse().unwrap();
    let mut y: i64 = itr.next().unwrap().parse().unwrap();
    let mut x: i64 = itr.next().unwrap().parse().unwrap();
    let mut a: std::collections::BinaryHeap<i64> = (0..n)
        .map(|_| itr.next().unwrap().parse().unwrap())
        .collect();

    while let Some(mut b) = a.pop() {
        if b < 0 {
            println!("Yes");
            return;
        } else if x == 0 && y == 0 && z == 0 {
            println!("No");
            return;
        }
        if x > 0 {
            if b / 10000 <= x {
                x -= b / 10000;
                if b < 10000 {
                    x -= 1;
                    b = -1;
                } else {
                    b %= 10000;
                }
            } else {
                b -= x * 10000;
                x = 0;
            }
        } else if y > 0 {
            if b / 5000 <= y {
                y -= b / 5000;
                if b < 5000 {
                    y -= 1;
                    b = -1;
                } else {
                    b %= 5000;
                }
            } else {
                b -= y * 5000;
                y = 0;
            }
        } else if z > 0 {
            if b / 1000 <= z {
                z -= b / 1000;
                if b < 1000 {
                    z -= 1;
                    b = -1;
                } else {
                    b %= 1000;
                }
            } else {
                b -= z * 1000;
                z = 0;
            }
        }
        a.push(b);
    }
}
0