結果
| 問題 | No.156 キャンディー・ボックス |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-02-08 18:01:41 |
| 言語 | Rust (1.93.0 + proconio + num + itertools) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 2,000 ms |
| コード長 | 762 bytes |
| 記録 | |
| コンパイル時間 | 1,441 ms |
| コンパイル使用メモリ | 202,176 KB |
| 実行使用メモリ | 7,848 KB |
| 最終ジャッジ日時 | 2026-02-08 18:01:45 |
| 合計ジャッジ時間 | 3,923 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 30 |
ソースコード
fn main() {
let stdin = std::io::read_to_string(std::io::stdin()).unwrap();
let mut stdin = stdin.split_ascii_whitespace();
let n: usize = stdin.next().unwrap().parse().unwrap();
let m: u32 = stdin.next().unwrap().parse().unwrap();
let c: Vec<u32> = (0..n)
.map(|_| stdin.next().unwrap().parse().unwrap())
.collect();
use std::io::Write;
std::io::stdout()
.write_all(output(solve(m, c)).as_bytes())
.unwrap();
}
fn solve(m: u32, mut c: Vec<u32>) -> usize {
c.sort_unstable();
let c = c;
let mut sum = 0;
c.into_iter()
.take_while(|&c| {
sum += c;
sum <= m
})
.count()
}
fn output(ans: usize) -> String {
ans.to_string() + "\n"
}