-
Notifications
You must be signed in to change notification settings - Fork 111
/
solution.py
35 lines (26 loc) · 820 Bytes
/
solution.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
#!/bin/python3
import os
import sys
#
# Complete the truckTour function below.
#
def truckTour(petrolpumps):
#
# Write your code here.
#
position=fuel=0
for i in range(len(petrolpumps)):
fuel+=petrolpumps[i][0]-petrolpumps[i][1] #calculating the remaining fuel after covering the distance given
if fuel<0: #if at that point, no fuel left
position=i+1 #we start from the next position
fuel =0 #and reset the fuel to zero to start over
return position
if __name__ == '__main__':
fptr = open(os.environ['OUTPUT_PATH'], 'w')
n = int(input())
petrolpumps = []
for _ in range(n):
petrolpumps.append(list(map(int, input().rstrip().split())))
result = truckTour(petrolpumps)
fptr.write(str(result) + '\n')
fptr.close()