Advertisement
Guest User

Untitled

a guest
Aug 31st, 2015
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.33 KB | None | 0 0
  1. import java.io.*;
  2. import java.util.*;
  3.  
  4. public class Solution {
  5.  
  6.     public void solve() throws IOException {
  7.         int n = in.nextInt();
  8.         int[] result = new int[n];
  9.         for (int i = 0; i < n; i++) {
  10.             result[i] = in.nextInt();
  11.         }
  12.         int max = 0;
  13.         int min = 0;
  14.         for (int i = 1; i < n; i++) {
  15.             if (result[i] > result[max]) {
  16.                 max = i;
  17.             }
  18.             if (result[i] <= result[min]) {
  19.                 min = i;
  20.             }
  21.         }
  22.  
  23.         System.out.println(max > min ? max + n - min - 2 : max + n - min - 1);
  24.     }
  25.  
  26.     public static String fileName = "";
  27.     public PrintWriter out;
  28.     MyScanner in;
  29.  
  30.     public void run() throws IOException {
  31.         in = new MyScanner();
  32.         out = new PrintWriter(System.out);
  33.         solve();
  34.         in.close();
  35.         out.close();
  36.     }
  37.  
  38.     public class MyScanner {
  39.         private BufferedReader br;
  40.         private StringTokenizer st;
  41.  
  42.         public MyScanner() throws IOException {
  43.             this.br = new BufferedReader(new InputStreamReader(System.in));
  44.         }
  45.  
  46.         public MyScanner(String fileTitle) throws IOException {
  47.             this.br = new BufferedReader(new FileReader(fileTitle));
  48.         }
  49.  
  50.         public String nextLine() throws IOException {
  51.             String s = br.readLine();
  52.             return s == null ? "-1" : s;
  53.         }
  54.  
  55.         public String next() throws IOException {
  56.             while (st == null || !st.hasMoreTokens()) {
  57.                 String s = br.readLine();
  58.                 if (s == null) {
  59.                     return "-1";
  60.                 }
  61.                 st = new StringTokenizer(s);
  62.             }
  63.             return st.nextToken();
  64.         }
  65.  
  66.         public int nextInt() throws IOException {
  67.             return Integer.parseInt(this.next());
  68.         }
  69.  
  70.         public long nextLong() throws IOException {
  71.             return Long.parseLong(this.next());
  72.         }
  73.  
  74.         public double nextDouble() throws IOException {
  75.             return Double.parseDouble(next());
  76.         }
  77.  
  78.         public void close() throws IOException {
  79.             this.br.close();
  80.         }
  81.     }
  82.  
  83.     public static void main(String[] args) throws IOException {
  84.         Locale.setDefault(Locale.US);
  85.         new Solution().run();
  86.     }
  87. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement