-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArrival of the General
More file actions
30 lines (25 loc) · 817 Bytes
/
Arrival of the General
File metadata and controls
30 lines (25 loc) · 817 Bytes
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
import java.io.*;
import java.util.*;
public class Main {
public static void main(String[] args) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int n = Integer.parseInt(br.readLine().trim());
StringTokenizer st = new StringTokenizer(br.readLine());
int max = -1, min = 101;
int maxPos = 0, minPos = 0;
for (int i = 0; i < n; i++) {
int h = Integer.parseInt(st.nextToken());
if (h > max) {
max = h;
maxPos = i;
}
if (h <= min) {
min = h;
minPos = i;
}
}
int result = maxPos + (n - 1 - minPos);
if (maxPos > minPos) result--;
System.out.print(result);
}
}