結果

問題 No.5 数字のブロック
ユーザー m0ntBL4Nc
提出日時 2019-09-08 16:17:00
言語 Rust
(1.83.0 + proconio)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 811 bytes
コンパイル時間 12,393 ms
コンパイル使用メモリ 378,760 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-06-27 15:02:38
合計ジャッジ時間 13,627 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 34
権限があれば一括ダウンロードができます

ソースコード

diff #

fn getline() -> String {
    let mut __ret = String::new();
    std::io::stdin().read_line(&mut __ret).ok();
    return __ret;
}

fn main() {
    let l: i32 = getline().trim().parse().unwrap();
    let n: i32 = getline().trim().parse().unwrap();
    let line = getline();
    let blockwidths_string: Vec<_> = line.trim().split(' ').collect();

    let mut blockwidths = Vec::new();
    for i in 0..n {
        let ui = i as usize;
        blockwidths.push(blockwidths_string[ui].parse::<i32>().unwrap());
    }

    blockwidths.sort();

    let mut block_count = 0;
    let mut blockwidth_total = 0;

    for blockwidth in &blockwidths {
        if blockwidth + blockwidth_total <= l {
            block_count += 1;
            blockwidth_total += blockwidth;
        }
    }

    println!("{}", block_count);
}
0