結果

問題 No.5 数字のブロック
ユーザー iwot
提出日時 2019-04-24 09:45:21
言語 Rust
(1.83.0 + proconio)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 697 bytes
コンパイル時間 10,849 ms
コンパイル使用メモリ 396,700 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-11-18 14:22:08
合計ジャッジ時間 11,942 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 34
権限があれば一括ダウンロードができます

ソースコード

diff #

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

fn main() {
    let mut space: i32 = read();
    let _num: usize = read();
    let mut blocks: Vec<i32> = read_vec();
    blocks.sort();

    let mut count = 0;
    for width in blocks {
        if space - width >= 0 {
            space -= width;
            count += 1;
        }
    }
    println!("{}", count);
}
0