title: Why am I getting Time limit exceeded for my this code?
body: <p>Why am i getting Time limit exceeded for ans for my this code?
  I tried this question on CodeChef.My logic is correct but my answer is showing time limit exceeded  , i don't know why ? </p>
  
  <p><a href="http://www.codechef.com/problems/CHEFRP" rel="nofollow">http://www.codechef.com/problems/CHEFRP</a></p>
  
  <pre><code>package test;
  import java.io.*;
  import java.util.*;
  public class Test 
  {
  
  
  public static void main(String[] args)throws IOException{
  
      int TESTCASES;
      BufferedReader br = new BufferedReader(new  InputStreamReader(System.in));
      TESTCASES=Integer.parseInt(br.readLine());
      int b=2*TESTCASES,i=0,m,l;
      int a;
      String[] lines=new String[b];
      int[] N=new int[TESTCASES];
      int[][] Ai =new int[TESTCASES][100001];  
      int[] min=new int[TESTCASES];
      int flag=0,minusonecase=-1;
      int[] sum=new int[TESTCASES]
  </code></pre>
  
  <p>;</p>
  
  <pre><code>    for(a=0;a&lt;b;a++)
      { 
          lines[a]=br.readLine();
          if(a%2==0)
          {
              N[a/2]=Integer.parseInt(lines[a]);
          }
          if(a%2!=0)
          {
              StringTokenizer stz=new StringTokenizer(lines[a]);
              for(l=0;l&lt;100001;l++)
              {
              if(stz.countTokens()!=0) 
              {
                      Ai[((a-1)/2)][l]=Integer.parseInt(stz.nextToken());  
              }
           else{
  
  
  
               break;
           }
  
  
  
  
          }
  
      }
  
      }       
  
      for(a=0;a&lt;TESTCASES;a++)
      {
          min[a]=Ai[a][0];
  
          for(l=0;l&lt;N[a];l++)
            {
                      if(min[a]&gt;Ai[a][l])
                      {
                          min[a]=Ai[a][l];
  
                      }
                  sum[a]=sum[a]+Ai[a][l];
  
          }
          sum[a]=sum[a]+2-min[a];
      }
  
         for(a=0;a&lt;TESTCASES;a++)
               {
                   for(l=0;l&lt;N[a];l++)
                   {
                       if(Ai[a][l]==1)
                       {  
                          System.out.println(minusonecase);
                          flag=1;
                          break;
  
                       }
  
                   }
                   if(flag==1)
                   {
                       flag=0;
                       continue;
                   }
                   System.out.println(sum[a]);
               }
  }
  }
  </code></pre>