Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from math import ceil
- eps = 10 ** -5
- vmax, d = map(int, input().split())
- n = int(input())
- x, t = [], []
- for i in range(n):
- row = input().split()
- x.append( int(row[0]) )
- h, m = map(int, row[1].split(':'))
- t.append( h * 60 + m )
- def float_equal(a, b):
- return abs(a - b) <= eps
- def float_less(a, b):
- return a < b and not float_equal(a, b)
- def float_less_or_equal(a, b):
- return float_equal(a, b) or float_less(a, b)
- def time_to_last(wait_time):
- time = wait_time
- position = 0
- cnt_eat = 0
- for i in range(n):
- time += (x[i] - position) / vmax
- if not float_less(time, t[i]) and i < n - 1:
- cnt_eat += 1
- time += d
- position = x[i]
- return time, cnt_eat
- left, right = 0, 10**9
- while float_less(left, right):
- mid = (left + right) / 2
- tlast, cnt_eat = time_to_last(mid)
- if float_less_or_equal(tlast, t[-1]):
- left = mid
- else:
- right = mid
- tlast, cnt_eat = time_to_last(right)
- time = ceil(tlast + x[-1] / vmax + (n - cnt_eat) * d - eps)
- print( "%02d:%02d" % ( time // 60, time % 60 ) )
Advertisement
Add Comment
Please, Sign In to add comment