[HackerRank][Python3] Truck Tour
2018. 9. 3. 21:45 |
프로그래밍/HackerRank
Problem :
https://www.hackerrank.com/challenges/truck-tour/problem
My Solution :
#!/usr/bin/env python3 def truck_tour(petrol_pumps): petrol_sum = distance_sum = i = j = 0 while True: if distance_sum + petrol_pumps[j % n][1] <= petrol_sum + petrol_pumps[j % n][0]: petrol_sum += petrol_pumps[j % n][0] distance_sum += petrol_pumps[j % n][1] j += 1 else: petrol_sum -= petrol_pumps[i][0] distance_sum -= petrol_pumps[i][1] i += 1 if n <= i: raise Exception('Can not find answer!') if i + n == j: return i n = int(input()) petrol_pumps = [] for _ in range(n): petrol_pumps.append(list(map(int, input().rstrip().split()))) result = truck_tour(petrol_pumps) print(result)
'프로그래밍 > HackerRank' 카테고리의 다른 글
[HackerRank][Python3] Beautiful Binary String (0) | 2018.09.05 |
---|---|
[HackerRank][Python3] Separate the Numbers (0) | 2018.09.04 |
[HackerRank][Python3] Weighted Uniform Strings (0) | 2018.09.04 |
[HackerRank][Python3] HackerRank in a String! (0) | 2018.09.03 |
[HackerRank][Python3] Waiter (0) | 2018.09.03 |
[HackerRank][Python3] Simple Text Editor (0) | 2018.09.02 |
[HackerRank][Python3] Equal Stacks (0) | 2018.09.02 |
[HackerRank][Python3] Maximum Element (0) | 2018.09.02 |
최근에 달린 댓글 최근에 달린 댓글