use std::collections::*; use std::io::Write; type Map = BTreeMap; type Set = BTreeSet; type Deque = VecDeque; fn main() { input! { n: usize, a: [i128; n], b: [i128; n], c: [i128; n], d: [i128; n], } let ans = if solve(a, b, c, d) { "Yes" } else { "No" }; println!("{}", ans); } fn solve(a: Vec, b: Vec, c: Vec, d: Vec) -> bool { let p = a.into_iter().zip(b).collect::>(); let q = c.into_iter().zip(d).collect::>(); if !yokohama(p.clone(), q.clone()) { return false; } for i in 0..p.len() { for j in 0..i { let mut p = p.clone(); let v = p.remove(i); p[j].0 += v.0; p[j].1 += v.1; if yokohama(p.clone(), q.clone()) { return true; } } } let mut ord = (0..p.len()).collect::>(); ord.sort_by(|a, b| { let x = q[*a]; let y = q[*b]; let z = p[*a]; let w = p[*b]; (x.0 * y.1 - x.1 * y.0) .cmp(&0) .then((z.0 * w.1 - z.1 * w.0).cmp(&0)) }); let s = ord.iter().map(|x| p[*x]).collect::>(); let t = ord.iter().map(|x| q[*x]).collect::>(); if valid(s, t) { return true; } todo!() } fn yokohama(mut p: Vec<(i128, i128)>, mut q: Vec<(i128, i128)>) -> bool { p.sort_by(|a, b| (a.0 * b.1 - a.1 * b.0).cmp(&0)); q.sort_by(|a, b| (a.0 * b.1 - a.1 * b.0).cmp(&0)); valid(p, q) } fn valid(p: Vec<(i128, i128)>, q: Vec<(i128, i128)>) -> bool { { let mut p = p.clone(); p.insert(0, (0, 0)); for i in 1..p.len() { p[i].0 += p[i - 1].0; p[i].1 += p[i - 1].1; } let mut x = 0; let mut y = 0; let mut pos = 0; for q in q.iter() { x += q.0; y += q.1; while x > p[pos + 1].0 { pos += 1; } let s = p[pos]; let t = p[pos + 1]; if (y - s.1) * (t.0 - s.0) > (t.1 - s.1) * (x - s.0) { return false; } } } { let mut q = q.clone(); q.insert(0, (0, 0)); for i in 1..q.len() { q[i].0 += q[i - 1].0; q[i].1 += q[i - 1].1; } let mut x = 0; let mut y = 0; let mut pos = 0; for p in p.iter() { x += p.0; y += p.1; while x > q[pos + 1].0 { pos += 1; } let s = q[pos]; let t = q[pos + 1]; if (y - s.1) * (t.0 - s.0) < (t.1 - s.1) * (x - s.0) { return false; } } } true } // ---------- begin input macro ---------- // reference: https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8 #[macro_export] macro_rules! input { (source = $s:expr, $($r:tt)*) => { let mut iter = $s.split_whitespace(); input_inner!{iter, $($r)*} }; ($($r:tt)*) => { let s = { use std::io::Read; let mut s = String::new(); std::io::stdin().read_to_string(&mut s).unwrap(); s }; let mut iter = s.split_whitespace(); input_inner!{iter, $($r)*} }; } #[macro_export] macro_rules! input_inner { ($iter:expr) => {}; ($iter:expr, ) => {}; ($iter:expr, $var:ident : $t:tt $($r:tt)*) => { let $var = read_value!($iter, $t); input_inner!{$iter $($r)*} }; } #[macro_export] macro_rules! read_value { ($iter:expr, ( $($t:tt),* )) => { ( $(read_value!($iter, $t)),* ) }; ($iter:expr, [ $t:tt ; $len:expr ]) => { (0..$len).map(|_| read_value!($iter, $t)).collect::>() }; ($iter:expr, chars) => { read_value!($iter, String).chars().collect::>() }; ($iter:expr, bytes) => { read_value!($iter, String).bytes().collect::>() }; ($iter:expr, usize1) => { read_value!($iter, usize) - 1 }; ($iter:expr, $t:ty) => { $iter.next().unwrap().parse::<$t>().expect("Parse error") }; } // ---------- end input macro ----------