-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMahmoud and a Triangle.cpp
More file actions
29 lines (26 loc) · 937 Bytes
/
Mahmoud and a Triangle.cpp
File metadata and controls
29 lines (26 loc) · 937 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
/*
Mahmoud has n line segments, the i-th of them has length ai. Ehab challenged him to use exactly 3
line segments to form a non-degenerate triangle. Mahmoud doesn't accept challenges unless he is sure he
can win, so he asked you to tell him if he should accept the challenge. Given the lengths of the line segments,
check if he can choose exactly 3 of them to form a non-degenerate triangle.
Mahmoud should use exactly 3 line segments, he can't concatenate two line segments or change any length.
A non-degenerate triangle is a triangle with positive area.
*/
#include<bits/stdc++.h>
using namespace std;
int main(){
int n;
cin >> n;
int arr[n];
for(int i = 0; i < n; i++)
cin >> arr[i];
sort(arr, arr + n);
for(int i = 0; i < n - 2; i++){
if(arr[i] + arr[i + 1] > arr[i + 2]){
cout << "YES" << endl;
return 0;
}
}
cout << "NO" << endl;
return 0;
}