-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathA.rs
More file actions
44 lines (40 loc) · 1.09 KB
/
A.rs
File metadata and controls
44 lines (40 loc) · 1.09 KB
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
/// Scanner class
/// Copied from https://codeforces.com/contest/1168/submission/54903799
///
/// Usage:
/// ```
/// let mut scanner = Scanner::default();
/// let n = scan.next::<i32>();
/// ```
#[derive(Default)]
struct Scanner {
buffer: Vec<String>
}
impl Scanner {
fn next<T: std::str::FromStr>(&mut self) -> T {
loop {
if let Some(token) = self.buffer.pop() {
return token.parse().ok().expect("Failed parsing input")
}
let mut input = String::new();
std::io::stdin().read_line(&mut input).expect("Failed reading input");
self.buffer = input.split_whitespace().rev().map(String::from).collect();
}
}
}
fn main() {
let mut scanner = Scanner::default();
let n_query = scanner.next::<usize>();
for _ in 0..n_query {
let vol = scanner.next::<i64>();
let price_1 = scanner.next::<i64>();
let price_2 = scanner.next::<i64>();
let solve = |vol, price_1, price_2| {
if price_2 >= price_1 * 2 {
return vol * price_1;
}
return (vol / 2) * price_2 + (vol % 2) * price_1;
};
println!("{}", solve(vol, price_1, price_2));
}
}