forked from anubhab91/CodeForces-5
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDragons.py
More file actions
44 lines (34 loc) · 1.04 KB
/
Dragons.py
File metadata and controls
44 lines (34 loc) · 1.04 KB
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
__author__ = 'deveshbajpai'
def pairSort(inputs):
for i in xrange(0,len(inputs)):
for j in xrange(1,len(inputs)):
if(
(inputs[i][0]>inputs[j][0])
or (inputs[i][0]==inputs[j][0] and inputs[i][1]<inputs[j][1])
):
print 'cond',inputs[i][0],inputs[i][1]
x_temp = inputs[i][0]
y_temp = inputs[i][1]
inputs[i][0] = inputs[j][0]
inputs[i][1] = inputs[j][1]
inputs[j][0] = x_temp
inputs[j][1] = y_temp
def solve(inputs,s):
pairSort(inputs)
print inputs
for i in xrange(0,len(inputs)):
if(s>inputs[i][0]):
s=s+inputs[i][1]
else:
return "NO"
return "YES"
if __name__ == "__main__":
s,n = map(int,raw_input().split(" "))
x = []
y = []
inputs = []
for _n in xrange(n):
x_val,y_val = map(int,raw_input().split(" "))
inputs.append([x_val,y_val])
#print inputs
print solve(inputs,s)