Codeforces 766B. Mahmoud and a Triangle Solution

Hints:

A non-degenerate triangle is a triangle that is, having a positive area.
If a,b and c are sides of the triangle, and if the following 3 conditions are true, then it is a non-degenerate triangle.
a+b>c
a+c>b
b+c>a
Solve in C++:
  1. ///**********ALLAH IS ALMIGHTY************///
  2. ///AH Tonmoy
  3. ///Department of CSE
  4. ///Islamic University,Bangladesh
  5. #include<iostream>
  6. #include<math.h>
  7. #include<algorithm>
  8. using namespace std;
  9. int main()
  10. {
  11. int ar[100009]= {0},m,n,i,j,c=0;
  12. while(cin>>n)
  13. {
  14. c=0;
  15. for(i=0; i<n; i++)
  16. cin>>ar[i];
  17. sort(ar,ar+n);
  18. for(i=0; i<n-2; i++)
  19. if(ar[i]+ar[i+1]>ar[i+2])
  20. {
  21. c=1;break;
  22. }
  23. if(c==1)
  24. cout<<"YES"<<endl;
  25. else
  26. cout<<"NO"<<endl;
  27. }
  28. return 0;
  29. }

No comments

Most View Post

Recent post

Codeforces Round 971 (Div. 4) 2009C. The Legend of Freya the Frog Solution

  Problem Link    https://codeforces.com/contest/2009/problem/C S olution in C++: /// Author : AH_Tonmoy #include < bits / stdc ++. h &g...

Powered by Blogger.