que 3

 avatar
unknown
java
a year ago
806 B
9
Indexable
import java.util.*;
import java.lang.*;
import java.io.*;

class Codechef
{
    public static void main(String[] args) throws java.lang.Exception
    {
        Scanner sc = new Scanner(System.in);
        int t = sc.nextInt();

        while (t > 0) {
            int n = sc.nextInt();
            int[] sales = new int[n];
            
            for (int i = 0; i < n; i++) {
                sales[i] = sc.nextInt();
            }

            long sum = 0;
            long max = 0;
            
            for(int j = 0; j< n ; j++){
                sum += (sales[j]*2);
                if(max < sum){
                    max = sum;
                }
                sum = sum - sales[j];
            }
            
            System.out.println(max);

            t--;
            }
        }
    }
Editor is loading...
Leave a Comment