766B Codeforces - Mahmoud and a triangle


766B Codeforces - Mahmoud and a triangle



Solution in c++

#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

int n;
vector<int> all;

int main()
{
    cin>>n;
    all.resize(n);
    for(int i=0;i<n;i++)cin>>all[i];
    sort(all.begin(),all.end());

    for(int i=0;i<n-2;i++)
    {
        for(int o=n-1;o>=i+2;o--)
        {

            int a=all[i],b=all[o],c=all[o-1];

            if(a+b>c && a+c>b && b+c>a)
            {
                cout<<"YES\n";
                return 0;
            }
        }
    }
    cout<<"NO\n";
    return 0;
}

Share on Google Plus

About Mohamed Sobhi

My name is Mo.Sobhy ,I study at School excelling high school in Ain Shams ,Cairo
My hobbies is programming ,and web development ,playing chess and writing horror stories.
    Blogger Comment
    Facebook Comment

0 التعليقات:

إرسال تعليق