-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patha_cookie_for_you.rs
80 lines (73 loc) · 1.79 KB
/
a_cookie_for_you.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
use std::collections::VecDeque;
use std::io;
fn can_do(a: u64, b: u64, n: u64, m: u64) -> bool {
if a + b < n + m {
return false;
}
if b == 0 || m == 0 {
return true;
}
if n == 0 {
if a > b {
return b >= m;
} else {
return a >= m;
}
}
if a > b {
let x = m.min(b);
return can_do(a, b - x, n, m - x);
} else {
let x = n.min(b);
return can_do(a, b - x, n - x, m);
}
}
fn solve1(scan: &mut Scan) -> io::Result<()> {
let a: u64 = scan.next();
let b: u64 = scan.next();
let n: u64 = scan.next();
let m: u64 = scan.next();
println!("{}", if can_do(a, b, n, m) { "Yes" } else { "No" });
Ok(())
}
fn main() -> io::Result<()> {
let mut scan = Scan::new();
let ts: usize = scan.next();
for _ in 0..ts {
solve1(&mut scan)?;
}
Ok(())
}
struct Scan {
buffer: VecDeque<String>,
}
impl Scan {
fn new() -> Scan {
Scan {
buffer: VecDeque::new(),
}
}
fn next_line(&self) -> io::Result<String> {
let mut line = String::new();
match io::stdin().read_line(&mut line)? {
0 => Err(io::Error::new(io::ErrorKind::Other, "EOF")),
_ => Ok(line),
}
}
fn next<T: std::str::FromStr>(&mut self) -> T {
loop {
if let Some(token) = self.buffer.pop_front() {
match token.parse() {
Ok(x) => {
return x;
}
_ => {
panic!("parse");
}
}
}
let line = self.next_line().unwrap();
self.buffer = line.split_whitespace().map(String::from).collect();
}
}
}