Polygon Possibility

You are given the length of n sides, you need to answer whether it is possible to make n sided convex polygon with it. 

Example:

Input:  n = 3, a = [4,3,2]
Output: Yes

Approach

C++

#include <bits/stdc++.h>
using namespace std;

bool polygonPossibility(long long nlong long a[])
{
    long long sum = 0max1 = a[0];
    for (long long i = 0i < ni++)
    {
        sum += a[i];
        max1 = max(max1a[i]);
    }
    if (sum - max1 > max1)
        return true;
    else
        return false;
}
int main()
{
    long long n = 3;
    long long a[n] = {432};

    if (polygonPossibility(na))
        cout << "Yes\n";
    else
        cout << "No\n";
    return 0;
}


No comments:

Post a Comment