#P3528. Triangle with Different-Coloured Sides
Triangle with Different-Coloured Sides
Triangle with Different-Coloured Sides
Little Johnny received a box of sticks of various lengths and colours from his grandparents. He wonders if there are three sticks in the set that can form a non-degenerate triangle (i.e. with positive area) with differently-coloured sides. In other words, you need to determine whether there exists a triple of sticks with distinct colours such that they satisfy the triangle inequality.
Recall that for three sides of lengths \(a\), \(b\) and \(c\) (after sorting them so that \(a \le b \le c\)), a triangle with positive area exists if and only if:
[ a + b > c ]
If such a triple exists, output "YES" on the first line and then output the three corresponding stick indices (1-indexed). Otherwise, output "NO".
inputFormat
The first line contains an integer \(n\) (\(3 \le n\le 10^5\)), the number of sticks.
Each of the following \(n\) lines contains an integer \(L\) (the length of the stick) and a string \(C\) (the colour of the stick), separated by a space.
It is guaranteed that the colours are arbitrary strings and the stick indices are from 1 to \(n\) in the order of input.
outputFormat
If there exist three sticks with distinct colours that can form a non-degenerate triangle, output "YES" on the first line and on the next line output three space-separated integers representing the indices (1-indexed) of the chosen sticks. If multiple answers are possible, output any one of them.
If no such triple exists, output "NO".
sample
3
3 red
4 blue
5 green
YES
1 2 3
</p>