-
Notifications
You must be signed in to change notification settings - Fork 0
/
corgi.py
49 lines (38 loc) · 1.31 KB
/
corgi.py
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
# single corgie refules
# deposits 1 kilo per ship
# loses 1 kilo per mile moved
firstLine = input().split(" ")
amountOfFuel = int(firstLine[0])
numShipRefuel = int(firstLine[1])
remainLines = int((numShipRefuel*(numShipRefuel-1))/2)
uniqueShips = []
entries = []
for i in range(remainLines):
user_input = input().split(" ")
numA = int(user_input[0]) #ship identifier A
numB = int(user_input[1]) #ship identifier B
numC = int(user_input[2]) #distance between 2 ships miles
entries.append([numA, numB, numC])
if(not numA in uniqueShips):
uniqueShips.append(numA)
if(not numB in uniqueShips):
uniqueShips.append(numB)
touchedEntries = [0]
sorted_entries = sorted(entries, key=lambda x: x[2])
paths = []
while len(touchedEntries) < len(uniqueShips):
entries_to_look_at = []
for item in sorted_entries:
if(item[0] in touchedEntries and not item in paths):
entries_to_look_at.append(item)
temp_sorted_entries = sorted(entries_to_look_at, key=lambda x: x[2])
if(len(temp_sorted_entries) != 0):
paths.append(temp_sorted_entries[0])
touchedEntries.append(temp_sorted_entries[0][1])
totalFuelUsed = len(uniqueShips)
for item in paths:
totalFuelUsed += item[2]
if(totalFuelUsed <= amountOfFuel):
print('yes')
else:
print('no')