-
Notifications
You must be signed in to change notification settings - Fork 2
/
interesting_drink_706B.rs
58 lines (43 loc) · 1.11 KB
/
interesting_drink_706B.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
// https://codeforces.com/contest/706/problem/B
// binary search
use std::io;
fn main() {
let mut n = String::new();
io::stdin()
.read_line(&mut n)
.unwrap();
let _n: i64 = n.trim().parse().unwrap();
let mut line = String::new();
io::stdin()
.read_line(&mut line)
.unwrap();
let mut x: Vec<i64> =
line
.split_whitespace()
.map(|x| x.parse().unwrap())
.collect();
x.sort();
let mut q = String::new();
io::stdin()
.read_line(&mut q)
.unwrap();
let q: i64 = q.trim().parse().unwrap();
for _ in 0..q {
let mut m = String::new();
io::stdin()
.read_line(&mut m)
.unwrap();
let m: i64 = m.trim().parse().unwrap();
let mut left: i64 = -1;
let mut right: i64 = x.len() as i64;
while (right-left) > 1 {
let middle = (left+right)/2;
if x[middle as usize] <= m {
left = middle;
} else {
right = middle;
}
}
println!("{}", right);
}
}