結果

問題 No.2424 Josouzai
ユーザー haihamabossuhaihamabossu
提出日時 2023-08-18 21:12:26
言語 Rust
(1.77.0)
結果
AC  
実行時間 52 ms / 2,000 ms
コード長 1,677 bytes
コンパイル時間 12,325 ms
コンパイル使用メモリ 377,080 KB
実行使用メモリ 14,848 KB
最終ジャッジ日時 2024-05-06 02:50:51
合計ジャッジ時間 15,256 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 1 ms
5,248 KB
testcase_02 AC 1 ms
5,248 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 15 ms
5,760 KB
testcase_05 AC 50 ms
14,848 KB
testcase_06 AC 51 ms
14,592 KB
testcase_07 AC 52 ms
14,592 KB
testcase_08 AC 41 ms
14,720 KB
testcase_09 AC 1 ms
5,376 KB
testcase_10 AC 8 ms
5,632 KB
testcase_11 AC 22 ms
13,056 KB
testcase_12 AC 17 ms
10,256 KB
testcase_13 AC 12 ms
5,760 KB
testcase_14 AC 21 ms
8,832 KB
testcase_15 AC 3 ms
5,376 KB
testcase_16 AC 35 ms
13,056 KB
testcase_17 AC 9 ms
5,376 KB
testcase_18 AC 11 ms
5,376 KB
testcase_19 AC 19 ms
7,808 KB
testcase_20 AC 36 ms
13,184 KB
testcase_21 AC 26 ms
10,624 KB
testcase_22 AC 12 ms
5,760 KB
testcase_23 AC 14 ms
6,528 KB
testcase_24 AC 6 ms
5,376 KB
testcase_25 AC 38 ms
13,824 KB
testcase_26 AC 27 ms
10,496 KB
testcase_27 AC 40 ms
14,464 KB
testcase_28 AC 35 ms
12,416 KB
testcase_29 AC 31 ms
11,392 KB
testcase_30 AC 8 ms
5,376 KB
testcase_31 AC 17 ms
7,424 KB
testcase_32 AC 40 ms
14,080 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

pub mod scanner {

    pub struct Scanner {
        buf: Vec<String>,
    }

    impl Scanner {
        pub fn new() -> Self {
            Self { buf: vec![] }
        }

        pub fn new_from(source: &str) -> Self {
            let source = String::from(source);
            let buf = Self::split(source);
            Self { buf }
        }

        pub fn next<T: std::str::FromStr>(&mut self) -> T {
            loop {
                if let Some(x) = self.buf.pop() {
                    return x.parse().ok().expect("");
                }
                let mut source = String::new();
                std::io::stdin().read_line(&mut source).expect("");
                self.buf = Self::split(source);
            }
        }

        fn split(source: String) -> Vec<String> {
            source
                .split_whitespace()
                .rev()
                .map(String::from)
                .collect::<Vec<_>>()
        }
    }
}

use crate::scanner::Scanner;
use std::io::Write;
fn main() {
    let mut scanner = Scanner::new();
    let out = std::io::stdout();
    let mut out = std::io::BufWriter::new(out.lock());
    let t: usize = 1;
    for _ in 0..t {
        solve(&mut scanner, &mut out);
    }
}
fn solve(scanner: &mut Scanner, out: &mut std::io::BufWriter<std::io::StdoutLock>) {
    let n: usize = scanner.next();
    let k: usize = scanner.next();
    let mut a = (0..n).map(|_| scanner.next::<usize>()).collect::<Vec<_>>();
    a.sort();
    let mut i = 0;
    let mut rem = k;
    while i < n {
        if rem < a[i] {
            break;
        }
        rem -= a[i];
        i += 1;
    }
    writeln!(out, "{} {}", i, rem).unwrap();
}
0