-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDragons.cpp
More file actions
47 lines (45 loc) · 772 Bytes
/
Dragons.cpp
File metadata and controls
47 lines (45 loc) · 772 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include <bits/stdc++.h>
using namespace std;
int main()
{
#ifndef ONLINE_JUDGE
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
#endif
int s,n,x,y,i,cnt=0,a[1000],b[1000],j;
scanf("%d%d",&s,&n);
for(i=0; i<n; i++)
{
scanf("%d%d",&x,&y);
a[i]=x;
b[i]=y;
}
for(i=0; i<n; i++)
{
for(j=0; j<n-i-1; j++)
{
if(a[j]>a[j+1])
{
swap(a[j],a[j+1]);
swap(b[j],b[j+1]);
}
}
}
for(i=0; i<n; i++)
{
if(s>a[i])
{
cnt++;
}
s+=b[i];
}
if(cnt==n)
{
printf("YES\n");
}
else
{
printf("NO\n");
}
return 0;
}