You are given length of n sides, you need to answer whether it is possible to make n sided convex polygon with it.
Input
First line contains no of testcases.
For each test case , first line consist of single integer ,second line consist of spaced integers, size of each side.
For each test case print "Yes" if it is possible to make polygon or else "No" if it is not possible.
Input
First line contains no of testcases.
For each test case , first line consist of single integer ,second line consist of spaced integers, size of each side.
2 3 4 3 2 4 1 2 1 4Output
For each test case print "Yes" if it is possible to make polygon or else "No" if it is not possible.
Yes No
Solution
import java.util.*;
class Polygon{
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int t=sc.nextInt();
while(t-->0)
{
int n=sc.nextInt();
int a[]=new int[n];
int sum=0;
for(int i=0;i<n;i++)
{
a[i]=sc.nextInt();
}
Arrays.sort(a);
int large=a[n-1];
for(int i=0;i<n-1;i++) //4 3 2 //1 1 2 4
{
sum+=a[i]; //9 8
}
if(sum>large)
System.out.println("Yes");
else
System.out.println("No");
}
}
}
Post a Comment