結果

問題 No.3016 ハチマキおじさん
ユーザー yiwiy9
提出日時 2025-01-25 14:18:18
言語 Rust
(1.83.0 + proconio)
結果
AC  
実行時間 81 ms / 2,000 ms
コード長 791 bytes
コンパイル時間 14,711 ms
コンパイル使用メモリ 398,964 KB
実行使用メモリ 27,344 KB
最終ジャッジ日時 2025-01-25 23:15:42
合計ジャッジ時間 17,821 ms
ジャッジサーバーID
(参考情報)
judge8 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 31
権限があれば一括ダウンロードができます

ソースコード

diff #

use std::collections::BTreeSet;

use proconio::input;

fn main() {
    input! {
        n: usize,
        mut a: [i64; n],
        mut b: [i64; n-1],
    }

    a.sort();
    b.sort();

    let mut cur = (0..n - 1).map(|i| (a[i] - b[i]).abs()).sum::<i64>();

    let mut map = std::collections::BTreeMap::new();
    map.insert(cur, BTreeSet::from([a[n - 1]]));

    for i in (0..n - 1).rev() {
        cur -= (a[i] - b[i]).abs();
        cur += (a[i + 1] - b[i]).abs();
        map.entry(cur).or_insert(BTreeSet::new()).insert(a[i]);
    }

    let min_set = map.iter().next().unwrap().1;

    println!("{}", min_set.len());
    println!(
        "{}",
        min_set
            .iter()
            .map(|&x| x.to_string())
            .collect::<Vec<_>>()
            .join(" ")
    );
}
0