結果

問題 No.818 Dinner time
ユーザー ngtkanangtkana
提出日時 2024-03-15 03:47:49
言語 Rust
(1.77.0)
結果
TLE  
実行時間 -
コード長 3,018 bytes
コンパイル時間 1,066 ms
コンパイル使用メモリ 188,288 KB
実行使用メモリ 13,480 KB
最終ジャッジ日時 2024-03-15 03:47:54
合計ジャッジ時間 5,352 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,548 KB
testcase_01 AC 0 ms
6,548 KB
testcase_02 AC 0 ms
6,548 KB
testcase_03 AC 2 ms
6,548 KB
testcase_04 AC 0 ms
6,548 KB
testcase_05 AC 1 ms
6,548 KB
testcase_06 AC 1 ms
6,548 KB
testcase_07 AC 1 ms
6,548 KB
testcase_08 AC 0 ms
6,548 KB
testcase_09 AC 1 ms
6,548 KB
testcase_10 AC 1 ms
6,548 KB
testcase_11 AC 1 ms
6,548 KB
testcase_12 AC 1 ms
6,548 KB
testcase_13 AC 1 ms
6,548 KB
testcase_14 AC 1 ms
6,548 KB
testcase_15 AC 1 ms
6,548 KB
testcase_16 AC 1 ms
6,548 KB
testcase_17 TLE -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

fn main() {
    let (n, m): (usize, usize) = io::input();
    let ab = (0..n)
        .map(|_| io::input::<(i64, i64)>())
        .collect::<Vec<_>>();

    let mut ans = i64::MIN;
    let mut dp = vec![0; m + 1];
    let g = |i: usize, a: i64, b: i64| (a * i as i64 + (b - a).max(0)).max(b);
    for i in 1..=m {
        dp[i] = g(m, ab[0].0, ab[0].1);
    }
    for &(a, b) in &ab[1..] {
        for i in 1..=m {
            dp[i] += g(i, a, b);
        }
        for i in (1..m).rev() {
            dp[i] = dp[i + 1].max(dp[i]);
        }
        ans = ans.max(dp[1]);
    }
    println!("{ans}");
}
// io {{{
// https://ngtkana.github.io/ac-adapter-rs/io/index.html

#[allow(dead_code)]
mod io {
    use std::cell::Cell;
    use std::io::stdin;
    use std::io::BufRead;
    use std::io::BufReader;
    use std::io::Lines;
    use std::io::Stdin;
    use std::sync::Mutex;
    use std::sync::Once;
    pub fn input<T: ParseLine>() -> T {
        ParseLine::parse_line(&line())
    }
    pub trait ParseLine {
        fn parse_line(s: &str) -> Self;
    }
    macro_rules! impl_parse_line {
        ($($t:ty),*) => {
            $(impl ParseLine for $t {
                fn parse_line(s: &str) -> Self {
                    s.parse().unwrap()
                }
            })*
        };
    }
    impl_parse_line!(u8, u16, u32, u64, u128, usize, i8, i16, i32, i64, i128, isize, String, char);
    macro_rules! impl_parse_line_tuple {
        ($($t:ident),*) => {
            impl<$($t: ParseLine),*> ParseLine for ($($t,)*) {
                fn parse_line(s: &str) -> Self {
                    let mut s = s.split_whitespace();
                    ($($t::parse_line(s.next().unwrap()),)*)
                }
            }
        };
    }
    impl_parse_line_tuple!(T0, T1);
    impl_parse_line_tuple!(T0, T1, T2);
    impl_parse_line_tuple!(T0, T1, T2, T3);
    impl_parse_line_tuple!(T0, T1, T2, T3, T4);
    impl_parse_line_tuple!(T0, T1, T2, T3, T4, T5);
    impl_parse_line_tuple!(T0, T1, T2, T3, T4, T5, T6);
    impl_parse_line_tuple!(T0, T1, T2, T3, T4, T5, T6, T7);
    impl_parse_line_tuple!(T0, T1, T2, T3, T4, T5, T6, T7, T8);
    impl_parse_line_tuple!(T0, T1, T2, T3, T4, T5, T6, T7, T8, T9);
    impl<T: ParseLine> ParseLine for Vec<T> {
        fn parse_line(s: &str) -> Self {
            s.split_whitespace().map(T::parse_line).collect()
        }
    }
    static ONCE: Once = Once::new();
    type Server = Mutex<Lines<BufReader<Stdin>>>;
    struct Lazy(Cell<Option<Server>>);
    unsafe impl Sync for Lazy {}
    fn line() -> String {
        static SYNCER: Lazy = Lazy(Cell::new(None));
        ONCE.call_once(|| {
            SYNCER
                .0
                .set(Some(Mutex::new(BufReader::new(stdin()).lines())));
        });
        unsafe {
            (*SYNCER.0.as_ptr())
                .as_ref()
                .unwrap()
                .lock()
                .unwrap()
                .next()
                .unwrap()
                .unwrap()
        }
    }
}
// }}}
0