結果

問題 No.1522 Unfairness
ユーザー akakimidoriakakimidori
提出日時 2021-05-28 21:43:40
言語 Rust
(1.77.0)
結果
AC  
実行時間 115 ms / 2,000 ms
コード長 2,529 bytes
コンパイル時間 1,059 ms
コンパイル使用メモリ 153,704 KB
実行使用メモリ 72,444 KB
最終ジャッジ日時 2023-08-12 07:27:47
合計ジャッジ時間 3,234 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 30 ms
20,428 KB
testcase_04 AC 8 ms
6,620 KB
testcase_05 AC 3 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 43 ms
29,144 KB
testcase_08 AC 43 ms
28,836 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 12 ms
9,528 KB
testcase_11 AC 6 ms
5,372 KB
testcase_12 AC 19 ms
14,080 KB
testcase_13 AC 63 ms
40,484 KB
testcase_14 AC 6 ms
5,104 KB
testcase_15 AC 114 ms
72,360 KB
testcase_16 AC 114 ms
72,392 KB
testcase_17 AC 115 ms
72,428 KB
testcase_18 AC 114 ms
72,444 KB
testcase_19 AC 114 ms
72,360 KB
testcase_20 AC 113 ms
72,432 KB
testcase_21 AC 1 ms
4,380 KB
testcase_22 AC 1 ms
4,380 KB
testcase_23 AC 1 ms
4,376 KB
testcase_24 AC 2 ms
4,380 KB
testcase_25 AC 1 ms
4,380 KB
testcase_26 AC 1 ms
4,376 KB
testcase_27 AC 1 ms
4,380 KB
testcase_28 AC 1 ms
4,380 KB
testcase_29 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

// ---------- begin chmin, chmax ----------
pub trait ChangeMinMax {
    fn chmin(&mut self, x: Self) -> bool;
    fn chmax(&mut self, x: Self) -> bool;
}

impl<T: PartialOrd> ChangeMinMax for T {
    fn chmin(&mut self, x: Self) -> bool {
        *self > x && {
            *self = x;
            true
        }
    }
    fn chmax(&mut self, x: Self) -> bool {
        *self < x && {
            *self = x;
            true
        }
    }
}
// ---------- end chmin, chmax ----------
// ---------- begin input macro ----------
// reference: https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};
    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
    ($iter:expr, bytes) => {
        read_value!($iter, String).bytes().collect::<Vec<u8>>()
    };
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}
// ---------- end input macro ----------

fn run() {
    input! {
        n: usize,
        m: usize,
        a: [usize; n],
    }
    let mut a = a;
    a.sort_by_key(|a| !*a);
    let mut dp = vec![vec![0; m + 1]; n + 1];
    for i in 0..(n - 1) {
        let (x, y) = (a[i] - a[i + 1], a[i]);
        for j in 0..=m {
            let v = dp[i][j];
            dp[i + 1][j].chmax(v);
        }
        if x <= m {
            for j in 0..=(m - x) {
                let v = dp[i][j];
                dp[i + 2][j + x].chmax(v + y);
            }
        }
    }
    let ans = dp.into_iter().flatten().max().unwrap();
    println!("{}", ans);
}

fn main() {
    run();
}
0