Skip to content

Commit

Permalink
typical90 007
Browse files Browse the repository at this point in the history
  • Loading branch information
bouzuya committed Feb 23, 2024
1 parent 1f52f84 commit 5f6e7bf
Showing 1 changed file with 22 additions and 4 deletions.
26 changes: 22 additions & 4 deletions cargo-atcoder-1.70.0/contests/typical90/src/bin/007.rs
@@ -1,10 +1,28 @@
use proconio::{input, marker::Usize1};
use proconio::input;
use superslice::Ext;

fn main() {
input! {
n: usize,
a: [Usize1; n],
mut a: [usize; n],
q: usize,
b: [usize; q],
};
let ans = n - a.len();
println!("{}", ans);

a.sort();

for b_i in b {
let j = a.lower_bound(&b_i);
let mut min = std::i64::MAX;
if let Some(&b_j) = a.get(j.saturating_sub(1)) {
min = min.min((b_i as i64 - b_j as i64).abs());
}
if let Some(&b_j) = a.get(j) {
min = min.min((b_i as i64 - b_j as i64).abs());
}
if let Some(&b_j) = a.get(j + 1) {
min = min.min((b_i as i64 - b_j as i64).abs());
}
println!("{}", min);
}
}

0 comments on commit 5f6e7bf

Please sign in to comment.