1103 characters | 42 lines | 1.08 KB
DOWNLOAD | RAW | EMBED | CREATE NEW VERSION OF THIS PASTE | REPORT ABUSE | x
  1. /*
  2.  * To change this template, choose Tools | Templates
  3.  * and open the template in the editor.
  4.  */
  5.  
  6.  
  7. import java.io.IOException;
  8. import java.util.Arrays;
  9. import java.util.Scanner;
  10.  
  11. /**
  12.  *
  13.  *
  14.  */
  15. public class yunsa {
  16.  
  17.     /**
  18.      * @param args the command line arguments
  19.      */
  20.     public static void main(String[] args) throws IOException {
  21.        Scanner sc = new Scanner(System.in);
  22.        int casos=sc.nextInt();
  23.        for (int i = 0; i < casos; i++) {
  24.            int alumnos=sc.nextInt();
  25.            int[]lista=new int[alumnos];
  26.            for (int j = 0; j < alumnos; j++) {
  27.                lista[j]=sc.nextInt();
  28.            }
  29.            Arrays.sort(lista, 0, lista.length);
  30.            int mayor=lista[1]-lista[0];
  31.            for (int j = 0; j < lista.length-2; j++) {
  32.                if (lista[j+2]-lista[j]>mayor)
  33.                    mayor=lista[j+2]-lista[j];
  34.            }
  35.            if (lista[alumnos-1]-lista[alumnos-2]>mayor)
  36.                    mayor=lista[alumnos-1]-lista[alumnos-2];
  37.            System.out.println(mayor);
  38.        }
  39.        
  40.     }
  41. }