MNMX - Editorial

What is wrong here except TLE(in subtask 3) ? I am curious … HELP !!

/* package codechef; // don’t place package name! */

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

/* Name of the class has to be “Main” only if the class is public. */
class Codechef
{
public static void main (String[] args) throws java.lang.Exception
{
// your code goes here
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();

	while(t-- > 0){
	    
	    int n = sc.nextInt();
	    ArrayList al = new ArrayList();
	    
	    for(int i=0;i<n;i++){
	        int x = sc.nextInt();
	        al.add(x);
	    }
	    
	    /*for(int i=0;i<n;i++){
	        System.out.println(al.get(i));
	    }*/
	    int sum = 0;
	    
	    while(al.size() > 1){
	        
	        if((int)al.get(0) > (int)al.get(1)){
	            sum = sum+(int)al.get(1);
	            al.remove(0);
	        }
	        else{
	            sum = sum+(int)al.get(0);
	            al.remove(1);
	        }
	        
	    }
	    
	    System.out.println(sum);
	}
	
}

}