Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.*;
- import java.util.*;
- public class Solution {
- public void solve() throws IOException {
- int n = in.nextInt();
- int[] result = new int[n];
- for (int i = 0; i < n; i++) {
- result[i] = in.nextInt();
- }
- int max = 0;
- int min = 0;
- for (int i = 1; i < n; i++) {
- if (result[i] > result[max]) {
- max = i;
- }
- if (result[i] <= result[min]) {
- min = i;
- }
- }
- System.out.println(max > min ? max + n - min - 2 : max + n - min - 1);
- }
- public static String fileName = "";
- public PrintWriter out;
- MyScanner in;
- public void run() throws IOException {
- in = new MyScanner();
- out = new PrintWriter(System.out);
- solve();
- in.close();
- out.close();
- }
- public class MyScanner {
- private BufferedReader br;
- private StringTokenizer st;
- public MyScanner() throws IOException {
- this.br = new BufferedReader(new InputStreamReader(System.in));
- }
- public MyScanner(String fileTitle) throws IOException {
- this.br = new BufferedReader(new FileReader(fileTitle));
- }
- public String nextLine() throws IOException {
- String s = br.readLine();
- return s == null ? "-1" : s;
- }
- public String next() throws IOException {
- while (st == null || !st.hasMoreTokens()) {
- String s = br.readLine();
- if (s == null) {
- return "-1";
- }
- st = new StringTokenizer(s);
- }
- return st.nextToken();
- }
- public int nextInt() throws IOException {
- return Integer.parseInt(this.next());
- }
- public long nextLong() throws IOException {
- return Long.parseLong(this.next());
- }
- public double nextDouble() throws IOException {
- return Double.parseDouble(next());
- }
- public void close() throws IOException {
- this.br.close();
- }
- }
- public static void main(String[] args) throws IOException {
- Locale.setDefault(Locale.US);
- new Solution().run();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement