Skip to content

Commit 6236e7f

Browse files
committed
add abc412c.rs
1 parent 2157bc9 commit 6236e7f

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed

src/abc/abc412c.rs

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/** THIS IS AN OUTPUT FILE. NOT EDIT THIS FILE DIRECTLY. **/
2+
use proconio::input;
3+
use proconio::marker::*;
4+
use std::marker::PhantomData;
5+
use std::cmp::*;
6+
use std::collections::*;
7+
8+
fn main() {
9+
input! {
10+
t:usize
11+
}
12+
13+
for _ in 0..t {
14+
helper();
15+
}
16+
}
17+
18+
fn helper() {
19+
let mut p = 0;
20+
let mut result = 1;
21+
22+
input! {
23+
n:usize,
24+
s:[usize;n]
25+
}
26+
27+
let mut success = true;
28+
loop {
29+
if 2 * s[p] >= s[n-1] {
30+
result += 1;
31+
break
32+
}
33+
34+
match s
35+
.iter()
36+
.enumerate()
37+
.filter(|&(_,&x)| x > s[p] && x <= 2 * s[p])
38+
.max_by_key(|&(_,&x)| x) {
39+
Some((i, _)) => {
40+
p = i;
41+
result += 1;
42+
}
43+
None => {
44+
println!("-1");
45+
success = false;
46+
break
47+
}
48+
}
49+
}
50+
51+
if success {
52+
println!("{}", result);
53+
}
54+
}

0 commit comments

Comments
 (0)