CodeForces 230A Dragons

你的名字 2022-02-22 16:10 301阅读 0赞

题目衔接:http://codeforces.com/problemset/problem/230/A

A. Dragons

time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

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 x**i, 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 y**i.

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 x**i and y**i (1 ≤ x**i ≤ 104, 0 ≤ y**i ≤ 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.

Example

input

Copy

  1. 2 2
  2. 1 99
  3. 100 0

output

Copy

  1. YES

input

Copy

  1. 10 1
  2. 100 100

output

Copy

  1. NO

Note

In the first sample Kirito’s strength initially equals 2. As the first dragon’s strength is less than 2, Kirito can fight it and defeat it. After that he gets the bonus and his strength increases to 2 + 99 = 101. Now he can defeat the second dragon and move on to the next level.

In the second sample Kirito’s strength is too small to defeat the only dragon and win.

题目大意:给你一个初始值,和n个怪物,杀死这个怪物可以获得能量,问你能不能杀死所有怪物,杀怪的顺序无要求

思路:虽然只是道A题,但这题我感觉可以拿出去吓人,,如果读不懂题意,或者误解了题意,这道题就可能认为是一道DP题……至少我刚开始就想成了dp,其实就是排个序,先杀死所有能杀死的龙,获取他们的能量,如果中间出现不能杀死的,肯定输出NO即可,遍历完输出YES就行了

代码:

  1. /*
  2. 题目大意:
  3. 思路:
  4. */
  5. #include<map>
  6. #include<set>
  7. #include <vector>
  8. #include<stack>
  9. #include<queue>
  10. #include<cmath>
  11. #include<string>
  12. #include<cstdio>
  13. #include<cstring>
  14. #include<cstdlib>
  15. #include<iostream>
  16. #include<algorithm>
  17. using namespace std;
  18. #define ll unsigned long long
  19. #define inf 0x3f3f3f
  20. #define esp 1e-8
  21. #define bug {printf("mmp\n");}
  22. #define mm(a,b) memset(a,b,sizeof(a))
  23. #define T() int test,q=1;scanf("%d",&test); while(test--)
  24. const int maxn=2e5+10;
  25. const double pi=acos(-1.0);
  26. const int N=201;
  27. const int mod=1e9+7;
  28. struct node
  29. {
  30. int s,g;
  31. } a[maxn];
  32. bool cmp(node a,node b)
  33. {
  34. if(a.s==b.s)
  35. return a.g>b.g;
  36. return a.s<b.s;
  37. }
  38. int main()
  39. {
  40. int ans,n;
  41. cin>>ans>>n;
  42. for(int i=0; i<n; i++)
  43. cin>>a[i].s>>a[i].g;
  44. sort(a,a+n,cmp);
  45. for(int i=0; i<n; i++)
  46. {
  47. if(ans<=a[i].s)
  48. {
  49. printf("NO\n");
  50. return 0;
  51. }
  52. else
  53. ans+=a[i].g;
  54. }
  55. cout<<"YES"<<endl;
  56. return 0;
  57. }

发表评论

表情:
评论列表 (有 0 条评论,301人围观)

还没有评论,来说两句吧...

相关阅读

    相关 CodeForces679A

    [CodeForces679A][] 也是交互题,这个要稍微难一些. 考虑的过程大概是: \\(1\\)肯定没有问的价值,如果问过\\(2\\),那么除了\\(4\

    相关 CodeForces1214A

    [CodeForces1214A][] 说起来你们可能不信,这题硬生生卡了我\\(1h\\),我想了背包,扩欧,二分....等等一坨办法.结果最后还是用了\\(bfs\\)

    相关 codeforce 141A

    /字符串问题 没AC的人可能是没看清楚题目吧, 先大概说下题目大意: 给你3个字符串,如果第一个串和第二个串组合在一起可以等于第三个串就输出“Y