viligen

scheduling_2

Feb 17th, 2022
758
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.43 KB | None | 0 0
  1. tasks = [int(n) for n in input().split(', ')]
  2. indx = int(input())
  3.  
  4. total_time = 0
  5. needed_task = tasks[indx]
  6. tasks_dict = {idx: value for idx, value in enumerate(tasks)}
  7.  
  8. sorted_tasks = sorted(tasks_dict.items(), key=lambda kvp: (kvp[1], kvp[0]))
  9. for index, value in sorted_tasks:
  10.     if (value < needed_task) or (value == needed_task and index <= indx):
  11.         total_time += value
  12.     else:
  13.         break
  14. print(total_time)
  15.  
  16.  
Advertisement
Add Comment
Please, Sign In to add comment