結果

問題 No.3434 [Cherry 8th Tune N] 大きくして Hold on Card!
コンテスト
ユーザー atcoder8
提出日時 2026-01-23 21:36:54
言語 Rust
(1.92.0 + proconio + num + itertools)
結果
AC  
実行時間 45 ms / 2,000 ms
コード長 818 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 4,681 ms
コンパイル使用メモリ 211,624 KB
実行使用メモリ 9,868 KB
最終ジャッジ日時 2026-01-23 21:37:38
合計ジャッジ時間 17,234 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 43
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

use itertools::{Itertools, enumerate};
use proconio::input;

fn main() {
    input! {
        t: usize,
    }

    let output = (0..t).map(|_| solve()).join("\n");
    println!("{output}");
}

fn solve() -> String {
    input! {
        n: usize,
        aa: [i64; n],
        bb: [i64; n],
    }

    let mut sum = aa.iter().sum::<i64>();
    let mut max_sum = sum;
    let mut max_changes = 0;

    let sorted_indices = (0..n).sorted_unstable_by_key(|&i| aa[i]).collect_vec();
    for (i, &j) in enumerate(&sorted_indices) {
        sum -= aa[j];
        sum += bb[i];
        if sum > max_sum {
            max_sum = sum;
            max_changes = i + 1;
        }
    }

    let mut answer = vec!['0'; n];
    for &i in &sorted_indices[..max_changes] {
        answer[i] = '1';
    }
    answer.iter().collect()
}
0