Trang

Thứ Hai, 3 tháng 1, 2011

3498. Differences

import java.io.*;
import java.math.BigInteger;

public class Main {

    /**
     * http://acm.tju.edu.cn/toj/showp3498.html
     * @author hunglee
     */
    public static void main(String[] args) throws IOException {
        
        BufferedReader in = new BufferedReader(
                new InputStreamReader(System.in));
        PrintWriter out = new PrintWriter(System.out);
        
        int ca, n;
        String[] s;
        ca = Integer.parseInt(in.readLine());
        while (ca-- > 0) {
            n = Integer.parseInt(in.readLine());
            s = in.readLine().split(" ");
            
            BigInteger min = new BigInteger(s[0]);
            BigInteger max = new BigInteger(s[0]);
            BigInteger j;
            for (int i = 1; i < n; ++i) {
                j = new BigInteger(s[i]);
                if (j.compareTo(max) > 0)
                    max = j;
                else if (j.compareTo(min) < 0)
                    min = j;
            }
            out.println(max.subtract(min));
        }
        out.flush();
    }

}

Không có nhận xét nào:

Đăng nhận xét