SWEA (SW Expert Academy)/D3

[SWEA/D3] 1860 진기의 최고급 붕어빵

hellosonic 2023. 4. 28. 00:00

문제 바로가기

 

SW Expert Academy

SW 프로그래밍 역량 강화에 도움이 되는 다양한 학습 컨텐츠를 확인하세요!

swexpertacademy.com

나의 코드 및 설명

t = int(input())
for test_case in range(1,t+1):
    n,m,k = map(int, input().split())
    customers = list(map(int, input().split()))
    customers.sort()
    max_time = max(customers)
    
    total = 0
    i = 0 
    ans = 1
    for time in range(0, max_time+1):
        if time != 0 and time % m == 0:
            total += k
        if time == customers[i]:
            if total >= 1:
                total -= 1
                i+=1
            else:
                ans = -1
                break
                
    if ans == 1:
        print("#{} {}".format(test_case, "Possible"))
    else:
        print("#{} {}".format(test_case, "Impossible"))

피드백

처음에는 while문을 이용해서 문제를 풀려다가 시간초과 에러로 인해 실패했다. for문으로 다시 풀어서 정답 판정을 받을 수 있었다.