forked from Vicfred/codeforces-rust
-
Notifications
You must be signed in to change notification settings - Fork 0
/
arrival_of_the_general_144A.rs
60 lines (46 loc) · 1.14 KB
/
arrival_of_the_general_144A.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
// https://codeforces.com/problemset/problem/144/A
// implementation, greedy
use std::io;
fn main() {
let mut n = String::new();
io::stdin()
.read_line(&mut n)
.unwrap();
let n: usize = n.trim().parse().unwrap();
let mut line = String::new();
io::stdin()
.read_line(&mut line)
.unwrap();
let words: Vec<i64> =
line
.split_whitespace()
.map(|x| x.parse().unwrap())
.collect();
let mut maxima = -1;
let mut minima = 101;
for item in &words {
if *item > maxima {
maxima = *item;
}
if *item < minima {
minima = *item;
}
}
let mut answer = 0;
for (idx, item) in words.clone().into_iter().enumerate() {
if item == maxima {
answer += idx;
break;
}
}
for (idx, item) in words.clone().into_iter().rev().enumerate() {
if item == minima {
answer += idx;
break;
}
}
if answer >= n {
answer -= 1;
}
println!("{}", answer);
}