Here's your approach:
Read your initial strength and number of dragons .
Store each dragon as a pair (strength, bonus) in a vector.
Sort the vector by dragon strength in ascending order.
Loop through the sorted dragons.
For each dragon, check if your current strength is greater than the dragon's strength.
If yes, add the bonus to your strength and continue.
If no, output "NO" and stop.
If you defeat all dragons, output "YES". This solution combines sorting with sequential checking. You sort once, then process in order. The sort does the hard work of finding the right sequence for you.