結果

問題 No.1950 片道きゃっちぼーる
ユーザー 👑 zeronosu77108zeronosu77108
提出日時 2022-05-20 23:25:24
言語 Rust
(1.77.0)
結果
WA  
実行時間 -
コード長 2,871 bytes
コンパイル時間 16,069 ms
コンパイル使用メモリ 171,304 KB
実行使用メモリ 28,648 KB
最終ジャッジ日時 2023-10-20 14:18:06
合計ジャッジ時間 10,515 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 1 ms
4,348 KB
testcase_02 AC 1 ms
4,348 KB
testcase_03 AC 113 ms
28,048 KB
testcase_04 AC 130 ms
28,072 KB
testcase_05 AC 0 ms
4,372 KB
testcase_06 AC 104 ms
27,392 KB
testcase_07 AC 74 ms
28,648 KB
testcase_08 AC 191 ms
26,952 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 100 ms
28,360 KB
testcase_12 AC 106 ms
28,368 KB
testcase_13 AC 134 ms
27,920 KB
testcase_14 AC 137 ms
27,128 KB
testcase_15 WA -
testcase_16 AC 107 ms
27,644 KB
testcase_17 AC 1 ms
4,372 KB
testcase_18 AC 122 ms
28,336 KB
testcase_19 WA -
testcase_20 AC 98 ms
28,152 KB
testcase_21 AC 150 ms
27,544 KB
testcase_22 AC 137 ms
27,424 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

use std::collections::BTreeMap;

fn main() {
    let n : usize = input();
    let x : Vec<usize> = input_vec();
    let a : Vec<usize> = input_vec();

    let mut index = (0..n).collect::<Vec<_>>();
    index.sort_by_key(|&i| x[i] + a[i]);

    let mut mp = BTreeMap::new();
    let mut ans = vec![0; n];
    for &i in index.iter().rev() {
        let x = x[i];
        let a = a[i];
        let base = *mp.get(&(x + a)).unwrap_or(&0);
        mp.insert(x, base + a);
        ans[i] = base + a;
    }

    for (i, (&x,&a)) in x.iter().zip(a.iter()).enumerate() {
        if x < a { continue }
        let base = *mp.get(&(x-a)).unwrap_or(&0);
        ans[i] = ans[i].max(base.saturating_sub(x));
        mp.insert(x, ans[i]);
    }
    for (i, (&x,&a)) in x.iter().zip(a.iter()).enumerate() {
        if x < a { continue }
        let base = *mp.get(&(x-a)).unwrap_or(&0);
        ans[i] = ans[i].max(base.saturating_sub(a));
        mp.insert(x, ans[i]);
    }

    println!("{}", ans.iter().map(|i| i.to_string()).collect::<Vec<_>>().join("\n"));
}

#[allow(dead_code)] fn input<T: std::str::FromStr>() -> T { let mut s = String::new(); std::io::stdin().read_line(&mut s).ok(); s.trim().parse().ok().unwrap() } #[allow(dead_code)] fn input_t<T: std::str::FromStr, U: std::str::FromStr>() -> (T, U) { let mut s = String::new(); std::io::stdin().read_line(&mut s).ok(); let s = s.trim().split_whitespace().collect::<Vec<&str>>(); (s[0].parse().ok().unwrap(), s[1].parse().ok().unwrap()) } #[allow(dead_code)] fn input_t3<T1: std::str::FromStr, T2: std::str::FromStr, T3: std::str::FromStr>() -> (T1, T2, T3) { let mut s = String::new(); std::io::stdin().read_line(&mut s).ok(); let s = s.trim().split_whitespace().collect::<Vec<&str>>(); (s[0].parse().ok().unwrap(), s[1].parse().ok().unwrap(), s[2].parse().ok().unwrap()) } #[allow(dead_code)] fn input_t4<T1: std::str::FromStr, T2: std::str::FromStr, T3: std::str::FromStr, T4: std::str::FromStr>() -> (T1, T2, T3, T4) { let mut s = String::new(); std::io::stdin().read_line(&mut s).ok(); let s = s.trim().split_whitespace().collect::<Vec<&str>>(); (s[0].parse().ok().unwrap(), s[1].parse().ok().unwrap(), s[2].parse().ok().unwrap(), s[3].parse().ok().unwrap()) } #[allow(dead_code)] fn input_t5<T1: std::str::FromStr, T2: std::str::FromStr, T3: std::str::FromStr, T4: std::str::FromStr, T5: std::str::FromStr>() -> (T1, T2, T3, T4, T5) { let mut s = String::new(); std::io::stdin().read_line(&mut s).ok(); let s = s.trim().split_whitespace().collect::<Vec<&str>>(); (s[0].parse().ok().unwrap(), s[1].parse().ok().unwrap(), s[2].parse().ok().unwrap(), s[3].parse().ok().unwrap(), s[4].parse().ok().unwrap()) } #[allow(dead_code)] fn input_vec<T: std::str::FromStr>() -> Vec<T> { let mut s = String::new(); std::io::stdin().read_line(&mut s).ok(); s.trim().split_whitespace().map(|s| s.parse().ok().unwrap()).collect() }
0