結果

問題 No.3325 陰陽師
コンテスト
ユーザー elphe
提出日時 2025-11-15 02:04:50
言語 Rust
(1.83.0 + proconio)
結果
AC  
実行時間 54 ms / 2,000 ms
コード長 1,339 bytes
コンパイル時間 13,821 ms
コンパイル使用メモリ 397,036 KB
実行使用メモリ 9,088 KB
最終ジャッジ日時 2025-11-15 02:05:09
合計ジャッジ時間 15,456 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 30
権限があれば一括ダウンロードができます

ソースコード

diff #

use proconio::{fastout, input};

#[fastout]
fn main() {
    input! {
        n: usize,
        m: usize,
        mut s: [u32; n],
        t: [u32; m],
    }
    s.sort_unstable();
    let mut sorted_t = t.into_iter().zip(0..m as u32).collect::<Vec<_>>();
	sorted_t.sort_unstable();
    println!("{}", output(solve(n, s, sorted_t)));
}

fn check(n: usize, s: &Vec<u32>, t: &Vec<(u32, u32)>, c: usize) -> bool {
    let mut i = 0;
    for (t, index) in t.iter() {
        if (*index as usize) < c {
            while i < n && s[i] < *t {
                i += 1;
            }
            match i < n {
                true => i += 1,
				false => return false,
            };
        }
    }
	true
}

fn solve(n: usize, s: Vec<u32>, t: Vec<(u32, u32)>) -> u32 {
    let mut l = 0;
    let mut r = t.len() + 1;
    while l + 1 < r {
        let c = (l + r) / 2;
        match check(n, &s, &t, c) {
            true => l = c,
            false => r = c,
        };
    }

	let mut ans = 0;
	let mut i = 0;
    for (t, index) in t.into_iter() {
        if (index as usize) < l {
            while i < n && s[i] < t {
                i += 1;
            }
            match i < n {
                true => ans = ans.max(s[i] - t),
				false => return ans,
            };
			i += 1;
        }
    }
	ans
}

fn output(ans: u32) -> u32 {
    ans
}
0