結果

問題 No.5 数字のブロック
ユーザー mtwtkman
提出日時 2019-10-14 11:34:13
言語 Rust
(1.83.0 + proconio)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 690 bytes
コンパイル時間 14,545 ms
コンパイル使用メモリ 379,600 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-12-23 12:52:30
合計ジャッジ時間 14,454 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 34
権限があれば一括ダウンロードができます
コンパイルメッセージ
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
        }
    }

    println!("{}", &ws.len());
}
0