동캄의 코딩도장

백준 7507 [올림픽 게임] 파이썬 본문

코테/BOJ

백준 7507 [올림픽 게임] 파이썬

동 캄 2022. 9. 4. 23:57

https://www.acmicpc.net/problem/7507

 

7507번: 올림픽 게임

각 테스트 케이스마다 "Scenario #i:"를 출력한다. 여기서 i는 테스트 케이스 번호이며 1부터 시작한다. 그 다음 줄에는 상근이가 참석할 수 있는 경기의 최대 개수를 출력한다. 문제에서도 설명했지

www.acmicpc.net

#백준 7507
import sys
tc=int(sys.stdin.readline())
for k in range(tc):
    n=int(sys.stdin.readline())
    lst=[]
    for _ in range(n):
        s=list(map(int,sys.stdin.readline().split()))
        lst.append(s)
    lst.sort(key=lambda x:(x[0],x[2],x[1]))
    day=0
    time=-1
    count=0
    for i in range(n):
        if lst[i][0]>day:
            day=lst[i][0]
            time=lst[i][2]
            count+=1
        else:
            if lst[i][1]>=time:
                time=lst[i][2]
                count+=1
    print('Scenario #{}:'.format(k+1))
    print(count)
    print()