-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathB_Alice_s_Adventures_in_Permuting.rs
81 lines (76 loc) · 1.7 KB
/
B_Alice_s_Adventures_in_Permuting.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
81
#![allow(unused)]
fn solve(scan: &mut Scanner, case: usize) {
let n: i128 = scan.next();
let b: i128 = scan.next();
let c: i128 = scan.next();
let (mut l, mut r) = (0, n);
let mut m = 0;
let mut calc = 0;
if b==0 {
if c>=n {
n.println();
} else if c==n-1 || c==n-2 {
(n-1).println();
}else {
"-1".println();
}
return;
}
if c>=n {
n.println();
}else {
(n-0.max(1+(n-c-1)/b)).println();
}
}
fn main() {
let mut scan = Scanner::new();
let t: usize = 1;
let t: usize = scan.next();
(1..=t).for_each(|case| solve(&mut scan, case));
}
trait Print {
fn println(&self);
}
impl<T: std::fmt::Display> Print for T {
fn println(&self) {
println!("{}", self);
}
}
trait Prints {
fn println(&self);
}
impl<T: std::fmt::Display> Prints for Vec<T> {
fn println(&self) {
if let Some((last, elements)) = self.split_last() {
for element in elements {
print!("{} ", element);
}
println!("{}", last);
}
}
}
struct Scanner {
arr: Vec<String>,
}
impl Scanner {
fn new() -> Self {
Self { arr: Vec::new() }
}
fn next<T: std::str::FromStr>(&mut self) -> T
where
T::Err: std::fmt::Debug,
{
if self.arr.is_empty() {
let mut input = String::new();
std::io::stdin().read_line(&mut input).unwrap();
self.arr = input.split_whitespace().rev().map(String::from).collect();
}
self.arr.pop().unwrap().parse().unwrap()
}
fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T>
where
T::Err: std::fmt::Debug,
{
(0..n).map(|_| self.next()).collect()
}
}