t = int(input())

for case in range(1, t+1):
    impossible = False
    n = int(input())
    activities = {i: list(map(int, input().split())) for i in range(n)}
    sorted_activities = sorted(activities.items(), key=lambda item: item[1])
    c = [sorted_activities[0][0]]
    j = []
    for activity in sorted_activities:
        if activity[0] not in c:
            if activities[c[-1]][1] <= activity[1][0]:
                c.append(activity[0])
            else:
                if len(j) == 0 or activities[j[-1]][1] <= activity[1][0]:
                    j.append(activity[0])
                else:
                    impossible = True
                    break
    if not impossible:
        result = ''
        for i in range(n):
            if i in c:
                result += 'C'
            elif i in j:
                result += 'J'
        print('Case #{}: {}'.format(case, result))
    else:
        print('Case #{}: IMPOSSIBLE'.format(case))


This was my approach using Python3

-- 
You received this message because you are subscribed to the Google Groups 
"Google Code Jam" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to google-code+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-code/3c62e48f-b2c5-4cc4-83df-e6392ba2a352%40googlegroups.com.

Reply via email to