Skip to content

Instantly share code, notes, and snippets.

@whatalnk
Created October 14, 2017 15:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save whatalnk/c1c7fea9e2bc71a9a60ac16f4d0cd472 to your computer and use it in GitHub Desktop.
Save whatalnk/c1c7fea9e2bc71a9a60ac16f4d0cd472 to your computer and use it in GitHub Desktop.
AtCoder ABC #075 D - Axis-Parallel Rectangle
use std::io;
use std::cmp;
fn gets() -> String {
let mut buf = String::new();
io::stdin().read_line(&mut buf).ok();
return buf
}
fn main() {
let line = gets();
let mut it = line.trim().split_whitespace().map(|n| n.parse::<usize>().unwrap());
let (n, k) = (it.next().unwrap(), it.next().unwrap());
let mut px = vec![0; n];
let mut py = vec![0; n];
let mut pxx = vec![0; n];
let mut pyy = vec![0; n];
for i in 0..n {
let line = gets();
let mut it = line.trim().split_whitespace().map(|n| n.parse::<i64>().unwrap());
let (x, y) = (it.next().unwrap(), it.next().unwrap());
px[i] = x;
py[i] = y;
pxx[i] = x;
pyy[i] = y;
}
pxx.sort();
pyy.sort();
let mut ans = (pxx[n-1] - pxx[0]) * (pyy[n-1] - pyy[0]);
for xi in 0..n {
for xj in (xi + 1)..n {
for yi in 0..n {
for yj in (yi + 1)..n {
let lx = pxx[xi];
let rx = pxx[xj];
let by = pyy[yi];
let uy = pyy[yj];
let mut num = 0;
for i in 0..n {
if lx <= px[i] && rx >= px[i] && by <= py[i] && uy >= py[i] {
num += 1;
}
}
if num >= k {
let area = (rx - lx) * (uy - by);
ans = cmp::min(ans, area);
}
}
}
}
}
println!("{}", ans);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment