#K33432. Safe Chandelier Installation
Safe Chandelier Installation
Safe Chandelier Installation
You are given a set of support beams with specified weight capacities and a number of chandeliers that need to be installed. Each chandelier has a weight and is supported by two beams (given as 1-based indices). A chandelier can be safely installed if and only if both of its designated beams have capacities greater than or equal to its weight.
Formally, given a chandelier with weight \(w\) to be installed on beams at indices \(i\) and \(j\), the installation is safe if \(B_i \ge w\) and \(B_j \ge w\), where \(B_i\) is the capacity of the \(i^{th}\) beam. Note that the beams are evaluated individually for each chandelier, and their capacities are not reduced when installing multiple chandeliers.
inputFormat
The input is read from standard input (stdin) and consists of multiple lines. The first line contains two space separated integers (n) and (m), where (n) is the number of beams and (m) is the number of chandeliers. The second line contains (n) space separated integers, each representing the weight capacity of a beam. The following (m) lines each contain three space separated integers (w), (i), and (j) indicating the weight of a chandelier and the 1-based indices of the two beams that will support it.
outputFormat
Output a single line to standard output (stdout) containing either "YES" if all the chandeliers can be safely installed, or "NO" if at least one chandelier cannot be safely installed.## sample
5 3
10 15 10 20 25
5 1 2
10 3 4
15 2 5
YES