Advertisement
Guest User

Untitled

a guest
Jun 24th, 2017
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.73 KB | None | 0 0
  1. T1 = 3
  2. T2 = 150
  3.  
  4. def solution(S):
  5. lines = S.split('\n')
  6. bill = {}
  7. max_cost = 0
  8. phone_with_max_cost = ''
  9. for line in lines:
  10. info = line.split(',')
  11. time = info[0]
  12. time_as_arr = time.split(':')
  13. hours = int(time_as_arr[0])
  14. minutes = int(time_as_arr[1])
  15. seconds = int(time_as_arr[2])
  16. if hours == 0 and minutes < 5:
  17. cost = (minutes*60+seconds)*T1
  18. else:
  19. minutes += hours*60
  20. cost = minutes*T2+int(seconds>0)*T2
  21. phone = info[1]
  22. if phone not in bill:
  23. bill[phone] = cost
  24. else:
  25. bill[phone] += cost
  26. if bill[phone] > max_cost:
  27. max_cost = bill[phone]
  28. phone_with_max_cost = phone
  29. bill[phone_with_max_cost] = 0
  30. total = 0
  31. for item in bill:
  32. total += bill[item]
  33. return total
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement