結果

問題 No.5 数字のブロック
コンテスト
ユーザー Tiramister
提出日時 2018-09-01 05:31:23
言語 Rust
(1.94.0 + proconio + num + itertools)
コンパイル:
/usr/bin/rustc_custom
実行:
./target/release/main
結果
AC  
実行時間 1 ms / 5,000 ms
コード長 737 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 9,789 ms
コンパイル使用メモリ 191,432 KB
実行使用メモリ 6,400 KB
最終ジャッジ日時 2026-05-13 00:24:46
合計ジャッジ時間 5,488 ms
ジャッジサーバーID
(参考情報)
judge1_1 / judge3_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 34
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

use std::io::*;
use std::str::FromStr;

fn get_line() -> String {
    let stdin = stdin();
    let mut line = String::new();
    stdin.lock().read_line(&mut line).expect("io error.");
    line.trim().to_string()
}

fn get_word<T: FromStr>() -> T {
    (&get_line()).parse().ok().expect("parse error.")
}

fn get_vec<T: FromStr>() -> Vec<T> {
    (&get_line()).split(' ').map(|x| x.parse().ok().expect("parse error.")).collect()
}

fn main () {
    let mut l = get_word::<i64>();
    get_word::<usize>();
    let mut wv = get_vec::<i64>();

    wv.sort();
    let mut ans: i64 = 0;
    for w in wv {
        l -= w;
        if l >= 0 {
            ans += 1;
        } else {
            break;
        }
    }

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