(UVA) Parking - Solution

import java.io.*;
import java.util.*;

class Main {
    public static void process() throws NumberFormatException, IOException {
        Scanner sc = new Scanner(System.in);
       
        int numCases = sc.nextInt();
        for (int i = 0; i < numCases; i++) {
            int numStores = sc.nextInt();
            int smaller = 10000;
            int bigger = -1;
            for (int j = 0; j < numStores; j++) {
                int store = sc.nextInt();
                if (store > bigger) {
                    bigger = store;  
                }
                if (store < smaller) {
                    smaller = store;
                }
            }
            System.out.println((bigger-smaller)*2);
        }
                               
        return;
    }
   
    public static void main(String[] args) throws NumberFormatException, IOException {
        Main m = new Main();
        m.process();
       
        System.exit(0);
    }
}

Comments

Popular posts from this blog

(Coderbyte) Powers of Two - Solução

(Coderbyte) Dash Insert II - Solução

(CoderByte) Number Search - Solução