結果

問題 No.156 キャンディー・ボックス
ユーザー cra77756176
提出日時 2022-11-29 23:40:37
言語 Rust
(1.83.0 + proconio)
結果
AC  
実行時間 1 ms / 2,000 ms
コード長 630 bytes
コンパイル時間 13,835 ms
コンパイル使用メモリ 383,348 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-10-07 08:58:25
合計ジャッジ時間 15,666 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 30
権限があれば一括ダウンロードができます

ソースコード

diff #

use std::io::{self, BufRead};

fn main() {
    let input = io::stdin()
        .lock()
        .lines()
        .map(|l| {
            l.unwrap()
                .split_whitespace()
                .map(|n| n.parse::<u64>().unwrap())
                .collect::<Vec<_>>()
        })
        .collect::<Vec<_>>();

    let m = input[0][1];

    let mut cc = input[1].clone();
    cc.sort_unstable();

    let cumsum = cc
        .iter()
        .scan(0, |sum, &c| {
            *sum += c;
            Some(*sum)
        })
        .collect::<Vec<_>>();

    println!("{}", cumsum.iter().position(|&n| n > m).unwrap_or(cc.len()));
}
0