Advertisement
ImranIF

CodejamQR

Apr 6th, 2020
722
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.03 KB | None | 0 0
  1. def solve(za):
  2.     za = [(za[i][0], za[i][1], i) for i in range(len(za))]
  3.  
  4.     za.sort(key=lambda x: x[0])
  5.  
  6.     imran = []
  7.  
  8.     c_end = 0
  9.     j_end = 0
  10.  
  11.     for start, end, idx in za:
  12.         if start < c_end and start < j_end:
  13.             return "IMPOSSIBLE"
  14.         elif start >= c_end:
  15.             imran.append(("C", idx))
  16.             c_end = end
  17.         else:  # elif start >= j_end:
  18.             imran.append(("J", idx))
  19.             j_end = end
  20.  
  21.     imran.sort(key=lambda x: x[1])  # sort according to the idx
  22.  
  23.     str_imran = ''
  24.  
  25.     for person, idx in imran:
  26.         str_imran += person
  27.  
  28.     return str_imran
  29.  
  30.  
  31. T = int(input().strip())
  32. list_imran = []
  33.  
  34. for i in range(1, T+1):
  35.     n = int(input().strip())
  36.  
  37.     za = []
  38.  
  39.     for ni in range(n):
  40.         interval = list(map(int, input().strip().split()))
  41.  
  42.         za.append(interval)
  43.  
  44.     imran = solve(za)
  45.  
  46.     list_imran.append(imran)
  47.  
  48. for index in range(len(list_imran)):
  49.     print("Case #{}: {}".format(index+1, list_imran[index]))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement