plaintext
function defeat_dragons(s, dragons)
// dragons is vector of pairs (strength, bonus)
sort(dragons) // sort by first element (strength)
current_strength := s
for each dragon in dragons
if current_strength > dragon.strength then
current_strength := current_strength + dragon.bonus
else
return "NO"
return "YES"
The time complexity is for sorting, where is the number of dragons.