CF 230A - Dragons
Kirito is stuck on a level of the MMORPG he is playing now. To move on in the game, he's got to defeat all n dragons that live on this level. Kirito and the dragons have strength, which is represented by an integer. In the duel between two opponents the duel's outcome is determined by their strength. Initially, Kirito's strength equals s.
If Kirito starts duelling with the i-th (1?≤?i?≤?n) dragon and Kirito's strength is not greater than the dragon's strength xi, then Kirito loses the duel and dies. But if Kirito's strength is greater than the dragon's strength, then he defeats the dragon and gets a bonus strength increase by yi.
Kirito can fight the dragons in any order. Determine whether he can move on to the next level of the game, that is, defeat all dragons without a single loss.
Input
The first line contains two space-separated integers s and n (1?≤?s?≤?104, 1?≤?n?≤?103). Then n lines follow: the i-th line contains space-separated integers xi and yi (1?≤?xi?≤?104, 0?≤?yi?≤?104) — the i-th dragon's strength and the bonus for defeating it.
Output
On a single line print "YES" (without the quotes), if Kirito can move on to the next level and print "NO" (without the quotes), if he can't.
-----------------------------------
桐人陷入了他現(xiàn)在正在玩的 MMORPG 的某個(gè)關(guān)卡。 為了在游戲中繼續(xù)前進(jìn),他必須擊敗生活在這一層的所有 n 條龍。 桐人與龍族的實(shí)力,是用整數(shù)來表示的。 在兩個(gè)對手之間的對決中,決斗的勝負(fù)取決于他們的實(shí)力。 最初,桐人的力量為s。
如果桐人開始與第 i (1?≤?i?≤?n) 條龍決斗,并且桐人的力量不大于龍的力量 xi,則桐人在決斗中失敗并死亡。 但如果桐人的力量大于龍的力量,那么他就會(huì)擊敗龍并獲得毅力的額外力量提升。
桐人可以以任何順序與龍戰(zhàn)斗。 確定他是否可以進(jìn)入游戲的下一個(gè)關(guān)卡,即以一敗涂地的方式擊敗所有龍。
輸入
第一行包含兩個(gè)空格分隔的整數(shù) s 和 n (1?≤?s?≤?104, 1?≤?n?≤?103)。 然后是 n 行:第 i 行包含空格分隔的整數(shù) xi 和 yi (1?≤?xi?≤?104, 0?≤?yi?≤?104) — 第 i 條龍的力量和擊敗它的獎(jiǎng)勵(lì)。
輸出
如果 Kirito 可以進(jìn)入下一個(gè)級別,則在單行中打印“YES”(不帶引號);如果不能,則打印“NO”(不帶引號)。
--------------------------------
打怪的快樂跟AC的快樂,哪個(gè)更快樂,雙倍快樂最好了。。