UVA 11364 – Parking

This one involves a bit of math. You will notice that it doesn’t matter where you park unless you park away from all of the shops.

import java.io.PrintWriter;
import java.util.Scanner;

/**
 * 
 * @author Sanchit M. Bhatnagar
 * @see http://uhunt.felix-halim.net/id/74004
 * 
 */
public class P11364 {

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    PrintWriter out = new PrintWriter(System.out);
    int T = sc.nextInt();
    while (T > 0) {
      int N = sc.nextInt();
      int min = Integer.MAX_VALUE;
      int max = Integer.MIN_VALUE;
      for (int i = 0; i < N; i++) {
        int next = sc.nextInt();
        min = Math.min(min, next);
        max = Math.max(max, next);
      }
      out.println(2 * (max - min));
      T--;
    }
    out.close();
    sc.close();
  }

}

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.