plz help in finding error in 1343C problem

Revision en1, by GuptaJi, 2020-04-22 16:17:02

import java.util.*; public class Main { public static int max(int[] arr, int start , int end) { int max = Integer.MIN_VALUE;

for( int i = start ; i<= end ; i++)
    {
        if(arr[i] > max)
        {
            max = arr[i];
        }

    }



   return max; 
}


public static void main(String[] args)
{
    Scanner scn = new Scanner(System.in);

    int t = scn.nextInt();

    for( int j = 1; j<= t ; j++ )
    {
        int n = scn.nextInt() ;
        int[] arr = new int[n];

        for(int i= 0; i < n  ; i++)
        {

            arr[i] = scn.nextInt();

        }


        int start = 0 ;
        int end ;
        long sum = 0 ;

        for( int i = 1 ; i < n ; i++)
        {
            long x = arr[start]*arr[i] ;
            if(x < 0)
            {
                end = i-1 ;


                sum = sum + max(arr,start ,end) ;

                start = i ;
            }



        }

        end = n-1 ; 
        sum = sum +  max(arr,start ,end) ;

    System.out.println(sum) ;
    }
}

}

Tags #help error

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en1 English GuptaJi 2020-04-22 16:17:02 1588 Initial revision (published)