結果

問題 No.710 チーム戦
ユーザー ngtkana
提出日時 2023-04-14 15:57:13
言語 Rust
(1.83.0 + proconio)
結果
AC  
実行時間 20 ms / 3,000 ms
コード長 970 bytes
コンパイル時間 12,200 ms
コンパイル使用メモリ 401,580 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2024-10-10 07:22:34
合計ジャッジ時間 13,661 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 25
権限があれば一括ダウンロードができます

ソースコード

diff #

use std::{convert::TryFrom, io::stdin, iter::repeat_with, usize::MAX};

fn main() {
    let stdin = stdin();
    let mut stdin = stdin.lines().map(Result::unwrap);
    let n = stdin.next().unwrap().parse::<usize>().unwrap();
    let ab = repeat_with(|| {
        <[_; 2]>::try_from(
            stdin
                .next()
                .unwrap()
                .split_whitespace()
                .map(|x| x.parse::<usize>().unwrap())
                .collect::<Vec<_>>(),
        )
        .unwrap()
    })
    .take(n)
    .collect::<Vec<_>>();
    let lim = ab.iter().map(|&[x, _]| x).sum::<usize>() + 1;
    let mut dp = vec![MAX; lim];
    dp[0] = 0;
    for &[x, y] in &ab {
        let mut swp = dp.iter().map(|&x| x.saturating_add(y)).collect::<Vec<_>>();
        for i in 0..lim - x {
            swp[i + x] = swp[i + x].min(dp[i]);
        }
        dp = swp;
    }
    let ans = (0..lim).map(|i| i.max(dp[i])).min().unwrap();
    println!("{}", ans);
}
0