My issue
What’s wrong with my approach
A0 + (n-2)(A1+…+An-1) +An <(n-1)(Bn+Bn-1)
My code
import java.util.*;
import java.lang.*;
import java.io.*;
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();
int[] a = new int[n];
int m1=0;
int m2=1;
a[0]=sc.nextInt();
a[1]=sc.nextInt();
for(int i=2;i<n;i++){
a[i] = sc.nextInt();
if(a[i]>a[m2] && m1!=m2)
m2=i;
if(a[i]>a[m1])
m1=i;
}
int b= a[m1]+a[m2];
long sum=0;
for(int i=1;i<n-1;i++)
sum+=(n-2)*a[i];
sum+=a[0]+a[n-1];
System.out.println(sum<(n-1)*b?"YES":"NO");
}
}
}
Problem Link: Chef And Adjacent Sums Practice Coding Problem