結果

問題 No.5 数字のブロック
ユーザー mtwtkman
提出日時 2019-10-14 11:32:41
言語 Rust
(1.83.0 + proconio)
結果
WA  
実行時間 -
コード長 658 bytes
コンパイル時間 14,526 ms
コンパイル使用メモリ 378,756 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-12-23 12:49:46
合計ジャッジ時間 16,096 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 24 WA * 10
権限があれば一括ダウンロードができます
コンパイルメッセージ
warning: unused variable: `n`
  --> src/main.rs:12:9
   |
12 |     let n = *&input[0].parse::<usize>().unwrap();
   |         ^ help: if this is intentional, prefix it with an underscore: `_n`
   |
   = note: `#[warn(unused_variables)]` on by default

ソースコード

diff #

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

fn read_stdin() -> Vec<String> {
    let mut buffer = String::new();
    io::stdin().read_to_string(&mut buffer).ok();
    buffer.trim().split('\n').map(|s| s.to_string()).collect()
}

fn main() {
    let input = read_stdin();
    let l = *&input[0].parse::<usize>().unwrap();
    let n = *&input[0].parse::<usize>().unwrap();
    let mut ws = input[2].split(' ').map(|s| s.parse::<usize>().unwrap()).collect::<Vec<usize>>();
    ws.sort();

    let mut result = 0;

    for (i, w) in ws.iter().enumerate() {
        result = result + w;
        if result > l {
            println!("{}", i);
            return
        }
    }
}
0