結果

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

ソースコード

diff #
raw source code

use std::io;

fn main() {
    let mut l = String::new();
    let mut n = String::new();
    let mut w = String::new();
    io::stdin().read_line(&mut l).unwrap();
    io::stdin().read_line(&mut n).unwrap();
    io::stdin().read_line(&mut w).unwrap();
    
    let l: u32 = l.trim().parse().unwrap();
    let n: u32 = n.trim().parse().unwrap();
    
    let mut w: Vec<u32> = w.trim().split_whitespace()
        .map(|x| x.parse::<u32>().unwrap() ).collect();
    
    w.sort_by(|a, b| a.cmp(b));
    
    let mut length = 0u32;
    let mut counter = 0u32;
    for i in 0..n {
        length += w[i as usize];
        
        if length > l {
            break;
        }
        else {
            counter += 1;
        }
        
    }
    
    println!("{}", counter);
}
0