結果

問題 No.2329 Nafmo、イカサマをする
ユーザー haihamabossuhaihamabossu
提出日時 2023-05-28 16:13:19
言語 Rust
(1.77.0)
結果
AC  
実行時間 109 ms / 2,000 ms
コード長 3,205 bytes
コンパイル時間 1,134 ms
コンパイル使用メモリ 151,972 KB
実行使用メモリ 13,204 KB
最終ジャッジ日時 2023-08-27 13:47:45
合計ジャッジ時間 3,565 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 1 ms
4,380 KB
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 1 ms
4,380 KB
testcase_17 AC 1 ms
4,376 KB
testcase_18 AC 3 ms
4,376 KB
testcase_19 AC 16 ms
4,376 KB
testcase_20 AC 5 ms
4,376 KB
testcase_21 AC 18 ms
4,424 KB
testcase_22 AC 3 ms
4,376 KB
testcase_23 AC 20 ms
4,660 KB
testcase_24 AC 8 ms
4,380 KB
testcase_25 AC 4 ms
4,376 KB
testcase_26 AC 6 ms
4,376 KB
testcase_27 AC 5 ms
4,380 KB
testcase_28 AC 3 ms
4,376 KB
testcase_29 AC 6 ms
4,380 KB
testcase_30 AC 3 ms
4,376 KB
testcase_31 AC 24 ms
5,596 KB
testcase_32 AC 1 ms
4,376 KB
testcase_33 AC 5 ms
4,376 KB
testcase_34 AC 7 ms
4,376 KB
testcase_35 AC 2 ms
4,376 KB
testcase_36 AC 41 ms
7,036 KB
testcase_37 AC 14 ms
4,380 KB
testcase_38 AC 79 ms
12,648 KB
testcase_39 AC 80 ms
13,204 KB
testcase_40 AC 80 ms
12,476 KB
testcase_41 AC 109 ms
12,448 KB
testcase_42 AC 79 ms
12,480 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

pub mod lower_bound {
    pub fn lower_bound<T: Ord>(list: &[T], val: &T) -> usize {
        let mut l = 0;
        let mut r = list.len();
        while l < r {
            let x = (l + r) / 2;
            match list[x].cmp(val) {
                std::cmp::Ordering::Less => {
                    l = x + 1;
                }
                std::cmp::Ordering::Equal | std::cmp::Ordering::Greater => {
                    r = x;
                }
            }
        }
        l
    }

    pub fn upper_bound<T: Ord>(list: &[T], val: &T) -> usize {
        let mut l = 0;
        let mut r = list.len();
        while l < r {
            let x = (l + r) / 2;
            match list[x].cmp(val) {
                std::cmp::Ordering::Less | std::cmp::Ordering::Equal => {
                    l = x + 1;
                }
                std::cmp::Ordering::Greater => {
                    r = x;
                }
            }
        }
        l
    }
}

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::{lower_bound::upper_bound, scanner::Scanner};

fn main() {
    let mut scanner = Scanner::new();
    let t: usize = 1;
    for _ in 0..t {
        solve(&mut scanner);
    }
}

fn solve(scanner: &mut Scanner) {
    let n: usize = scanner.next();
    let m: usize = scanner.next();
    let k: usize = scanner.next();
    let mut a = vec![0; n];
    for i in 0..n {
        let x = scanner.next::<usize>();
        a[i] = x;
    }
    if n == 0 || m == 0 {
        println!("0");
        return;
    }
    let mut b = vec![vec![]; 4];
    for i in 0..n {
        b[1].push(a[i]);
        for j in 0..n {
            b[2].push(a[i] + a[j]);
            for k in 0..n {
                b[3].push(a[i] + a[j] + a[k]);
            }
        }
    }
    for i in 0..4 {
        b[i].push(0);
        b[i].sort();
    }
    let mut ans = 0;
    for ki in 1..=k {
        let mut bi = 0;
        let mut bj = ki;
        if bj > 3 {
            bi = bj - 3;
            bj = 3;
        }
        for &x in b[bi].iter() {
            if m < x {
                break;
            }
            let i = upper_bound(&b[bj], &(m - x)) - 1;
            let y = b[bj][i];
            if x + y <= m {
                ans = ans.max(x + y);
            }
        }
    }
    println!("{}", ans);
}
0