CodeForces 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.

Sample test(s)

input

2 21 99100 0

output

YES

input

10 1100 100

output

NO

小技巧:结构体排序

struct Dragon{

int x,y;

bool operator < (const Dragon &rhs) const{

return x < rhs.x;

}

}dragon[1010];

sort(dragon,dragon+n);

或者

int cmp(Dragon a,Dragon b){

return a.x < b.x;

}

sort(dragon,dragon+n,cmp);

 1 #include <cstdio>
 2 #include <algorithm>
 3 using namespace std;
 4 const int maxn = 1010;
 5 struct Dragon{
 6     int x,y;
 7     bool operator < (const Dragon &rhs) const{
 8         return x < rhs.x;
 9      }
10 }dragon[1010];
11
12 int main(){
13     int s,n;
14     scanf("%d%d",&s,&n);
15     for(int i = 0;i < n;i++){
16         scanf("%d%d",&dragon[i].x,&dragon[i].y);
17     }
18     sort(dragon,dragon+n);
19     bool flag = 1;
20     for(int i = 0;i < n;i++){
21         if(s <= dragon[i].x){
22             flag = 0;
23             break;
24         }else{
25             s += dragon[i].y;
26         }
27     }
28     if(flag)    puts("YES");
29     else        puts("NO");
30     return 0;
31 }

CodeForces 230A Dragons,布布扣,bubuko.com

时间: 2025-01-03 22:17:00

CodeForces 230A Dragons的相关文章

CodeForces 230A

简单的一个排序+贪心 #include <iostream> #include <algorithm> using namespace std; struct peo{ int x,y; }; bool com(peo a,peo b){ return a.x<b.x; } peo l[1000]; int main() { int s,n; cin>>s>>n; for(int i=0;i<n;i++){ cin>>l[i].x&g

Codeforce 230A - Dragons (sort)

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

CSU-ACM2014暑假集训基础组训练赛(1) 解题报告

•Problem A HDU 4450                 水题,签到题 水题..没啥好说的.给大家签到用的. 1 #include <cstdio> 2 int main(){ 3 int n,a,ans; 4 while(scanf("%d",&n),n){ 5 ans = 0; 6 for(int i = 0;i < n;i++){ 7 scanf("%d",&a); 8 ans += a*a; 9 } 10 pr

Codeforces Round #105 (Div. 2) (ABCDE题解)

比赛链接:http://codeforces.com/contest/148 比较简单的一场,最长的一题也才写了30行多一点 A. Insomnia cure time limit per test:2 seconds memory limit per test:256 megabytes ?One dragon. Two dragon. Three dragon?, - the princess was counting. She had trouble falling asleep, and

Codeforces Gym 100513F F. Ilya Muromets 线段树

F. Ilya Muromets Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100513/problem/F Description I Ilya Muromets is a legendary bogatyr. Right now he is struggling against Zmej Gorynych, a dragon with n heads numbered from 1 to nf

【codeforces 718E】E. Matvey&#39;s Birthday

题目大意&链接: http://codeforces.com/problemset/problem/718/E 给一个长为n(n<=100 000)的只包含‘a’~‘h’8个字符的字符串s.两个位置i,j(i!=j)存在一条边,当且仅当|i-j|==1或s[i]==s[j].求这个无向图的直径,以及直径数量. 题解:  命题1:任意位置之间距离不会大于15. 证明:对于任意两个位置i,j之间,其所经过每种字符不会超过2个(因为相同字符会连边),所以i,j经过节点至多为16,也就意味着边数至多

Codeforces 124A - The number of positions

题目链接:http://codeforces.com/problemset/problem/124/A Petr stands in line of n people, but he doesn't know exactly which position he occupies. He can say that there are no less than a people standing in front of him and no more than b people standing b

Codeforces 841D Leha and another game about graph - 差分

Leha plays a computer game, where is on each level is given a connected graph with n vertices and m edges. Graph can contain multiple edges, but can not contain self loops. Each vertex has an integer di, which can be equal to 0, 1 or  - 1. To pass th

Codeforces Round #286 (Div. 1) A. Mr. Kitayuta, the Treasure Hunter DP

链接: http://codeforces.com/problemset/problem/506/A 题意: 给出30000个岛,有n个宝石分布在上面,第一步到d位置,每次走的距离与上一步的差距不大于1,问走完一路最多捡到多少块宝石. 题解: 容易想到DP,dp[i][j]表示到达 i 处,现在步长为 j 时最多收集到的财富,转移也不难,cnt[i]表示 i 处的财富. dp[i+step-1] = max(dp[i+step-1],dp[i][j]+cnt[i+step+1]) dp[i+st