結果

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

ソースコード

diff #

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