Skip to content

Commit

Permalink
tessoku-book a42, b42
Browse files Browse the repository at this point in the history
  • Loading branch information
bouzuya committed Oct 31, 2022
1 parent d5d828e commit baae53a
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 6 deletions.
18 changes: 15 additions & 3 deletions tessoku-book/src/bin/a42.rs
@@ -1,10 +1,22 @@
use proconio::{input, marker::Usize1};
use proconio::input;

fn main() {
input! {
n: usize,
a: [Usize1; n],
k: i64,
ab: [(i64, i64); n],
};
let ans = n - a.len();
let mut max = 0_usize;
for x in ab.iter().copied().map(|(x, _)| x) {
for y in ab.iter().copied().map(|(_, y)| y) {
let count = ab
.iter()
.copied()
.filter(|&(a_i, b_i)| (x..=x + k).contains(&a_i) && (y..=y + k).contains(&b_i))
.count();
max = max.max(count);
}
}
let ans = max;
println!("{}", ans);
}
25 changes: 22 additions & 3 deletions tessoku-book/src/bin/b42.rs
@@ -1,10 +1,29 @@
use proconio::{input, marker::Usize1};
use proconio::input;

fn main() {
input! {
n: usize,
a: [Usize1; n],
ab: [(i64, i64); n],
};
let ans = n - a.len();

let mut max = 0_i64;
for s1 in &[false, true] {
for s2 in &[false, true] {
let mut sum = 0_i64;
for (a, b) in ab.iter().copied() {
let score = match (s1, s2) {
(true, true) => a + b,
(true, false) => a - b,
(false, true) => -a + b,
(false, false) => -a - b,
};
if score > 0 {
sum += score;
}
}
max = max.max(sum);
}
}
let ans = max;
println!("{}", ans);
}

0 comments on commit baae53a

Please sign in to comment.