codeforces-scrape

Codeforces scraped problems and editorials
git clone git://git.laack.co/codeforces-scrape.git
Log | Files | Refs | README

766B.md (1408B)


      1 Source: https://codeforces.com/problemset/problem/766/B
      2 
      3 B. Mahmoud and a Triangle
      4 
      5 time limit per test
      6 
      7 2 seconds
      8 
      9 memory limit per test
     10 
     11 256 megabytes
     12 
     13 input
     14 
     15 standard input
     16 
     17 output
     18 
     19 standard output
     20 
     21 Mahmoud has *n* line segments, the *i*-th of them has length *a**i*. 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.
     22 
     23 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.
     24 
     25 Input
     26 
     27 The first line contains single integer *n* (3 ≤ *n* ≤ 105) — the number of line segments Mahmoud has.
     28 
     29 The second line contains *n* integers *a*1, *a*2, ..., *a**n* (1 ≤ *a**i* ≤ 109) — the lengths of line segments Mahmoud has.
     30 
     31 Output
     32 
     33 In the only line print "YES" if he can choose exactly three line segments and form a non-degenerate triangle with them, and "NO" otherwise.
     34 
     35 Examples
     36 
     37 Input
     38 
     39 ```
     40 5  
     41 1 5 3 2 4
     42 ```
     43 
     44 Output
     45 
     46 ```
     47 YES
     48 ```
     49 
     50 Input
     51 
     52 ```
     53 3  
     54 4 1 2
     55 ```
     56 
     57 Output
     58 
     59 ```
     60 NO
     61 ```
     62 
     63 Note
     64 
     65 For the first example, he can use line segments with lengths 2, 4 and 5 to form a non-degenerate triangle.