Jacob_Thomas

My code for 'Best Index'

Jun 10th, 2019
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.03 KB | None | 0 0
  1.  import java.util.*;
  2. class bestindex
  3. {
  4.     public static void main(String []args)
  5.     {
  6.         Scanner sc=new Scanner(System.in);
  7.         int n=sc.nextInt();
  8.         long arr[]=new long[n];
  9.         long brr[]=new long[n];
  10.         String s="";
  11.         long h=brr[0];
  12.         for(int x=0;x<n;x++)
  13.         {
  14.             s=sc.next();
  15.             arr[x]=Integer.valueOf(s);
  16.             brr[x]=0;
  17.         }
  18.         for(int x=0;x<n;x++)
  19.         {
  20.            
  21.            
  22.            int y=x;
  23.            int z=x;
  24.            int c=0;
  25.            while(z<n)
  26.            {
  27.                for(int i=y;i<=z;i++)
  28.                {
  29.                  brr[x]=brr[x]+arr[i];
  30.                 }
  31.                 y=z+1;
  32.                 c++;
  33.                 z=y+c;
  34.                
  35.             }
  36.            if(brr[x]>h)
  37.         h=brr[x];
  38.            
  39.            
  40.         }
  41.        
  42.        
  43.        
  44.         System.out.print(h);
  45.              
  46.                
  47.              
  48.        
  49.        
  50.        
  51.      
  52.      
  53.     }
  54. }
Add Comment
Please, Sign In to add comment