結果
問題 |
No.5 数字のブロック
|
ユーザー |
|
提出日時 | 2019-04-23 22:10:41 |
言語 | Rust (1.83.0 + proconio) |
結果 |
RE
|
実行時間 | - |
コード長 | 717 bytes |
コンパイル時間 | 16,190 ms |
コンパイル使用メモリ | 378,428 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-10-15 20:01:45 |
合計ジャッジ時間 | 15,841 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 24 RE * 10 |
コンパイルメッセージ
warning: unnecessary parentheses around `if` condition --> src/main.rs:25:12 | 25 | if (space < 0) { | ^ ^ | = note: `#[warn(unused_parens)]` on by default help: remove these parentheses | 25 - if (space < 0) { 25 + if space < 0 { |
ソースコード
fn read<T: std::str::FromStr>() -> T { let mut s = String::new(); std::io::stdin().read_line(&mut s).ok(); s.trim().parse().ok().unwrap() } fn read_vec<T: std::str::FromStr>() -> Vec<T> { let mut s = String::new(); std::io::stdin().read_line(&mut s).ok(); s.trim() .split_whitespace() .map(|e| e.parse().ok().unwrap()) .collect() } fn main() { let mut space: i32 = read(); let num: i32 = read(); let mut blocks: Vec<i32> = read_vec(); blocks.sort(); let mut count = 0; for i in 0..=(num as usize) { space = space - blocks[i]; if (space < 0) { break; } count += 1; } println!("{}", count); }