DevYoon

[ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค] ๊ณผ์ œ ์ง„ํ–‰ํ•˜๊ธฐ (Python) ๋ณธ๋ฌธ

PS/Programmers

[ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค] ๊ณผ์ œ ์ง„ํ–‰ํ•˜๊ธฐ (Python)

gimewn 2023. 4. 4. 12:49

link ๐Ÿ”— https://school.programmers.co.kr/learn/courses/30/lessons/176962

 

ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค

์ฝ”๋“œ ์ค‘์‹ฌ์˜ ๊ฐœ๋ฐœ์ž ์ฑ„์šฉ. ์Šคํƒ ๊ธฐ๋ฐ˜์˜ ํฌ์ง€์…˜ ๋งค์นญ. ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค์˜ ๊ฐœ๋ฐœ์ž ๋งž์ถคํ˜• ํ”„๋กœํ•„์„ ๋“ฑ๋กํ•˜๊ณ , ๋‚˜์™€ ๊ธฐ์ˆ  ๊ถํ•ฉ์ด ์ž˜ ๋งž๋Š” ๊ธฐ์—…๋“ค์„ ๋งค์นญ ๋ฐ›์œผ์„ธ์š”.

programmers.co.kr

 

๋ฌธ์ œ ์„ค๋ช…

 

๊ณผ์ œ๋ฅผ ๋ฐ›์€ ๋ฃจ๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™์€ ์ˆœ์„œ๋Œ€๋กœ ๊ณผ์ œ๋ฅผ ํ•˜๋ ค๊ณ  ๊ณ„ํš์„ ์„ธ์› ์Šต๋‹ˆ๋‹ค.

  • ๊ณผ์ œ๋Š” ์‹œ์ž‘ํ•˜๊ธฐ๋กœ ํ•œ ์‹œ๊ฐ์ด ๋˜๋ฉด ์‹œ์ž‘ํ•ฉ๋‹ˆ๋‹ค.
  • ์ƒˆ๋กœ์šด ๊ณผ์ œ๋ฅผ ์‹œ์ž‘ํ•  ์‹œ๊ฐ์ด ๋˜์—ˆ์„ ๋•Œ, ๊ธฐ์กด์— ์ง„ํ–‰ ์ค‘์ด๋˜ ๊ณผ์ œ๊ฐ€ ์žˆ๋‹ค๋ฉด ์ง„ํ–‰ ์ค‘์ด๋˜ ๊ณผ์ œ๋ฅผ ๋ฉˆ์ถ”๊ณ  ์ƒˆ๋กœ์šด ๊ณผ์ œ๋ฅผ ์‹œ์ž‘ํ•ฉ๋‹ˆ๋‹ค.
  • ์ง„ํ–‰์ค‘์ด๋˜ ๊ณผ์ œ๋ฅผ ๋๋ƒˆ์„ ๋•Œ, ์ž ์‹œ ๋ฉˆ์ถ˜ ๊ณผ์ œ๊ฐ€ ์žˆ๋‹ค๋ฉด, ๋ฉˆ์ถฐ๋‘” ๊ณผ์ œ๋ฅผ ์ด์–ด์„œ ์ง„ํ–‰ํ•ฉ๋‹ˆ๋‹ค.
  • ๋งŒ์•ฝ, ๊ณผ์ œ๋ฅผ ๋๋‚ธ ์‹œ๊ฐ์— ์ƒˆ๋กœ ์‹œ์ž‘ํ•ด์•ผ ๋˜๋Š” ๊ณผ์ œ์™€ ์ž ์‹œ ๋ฉˆ์ถฐ๋‘” ๊ณผ์ œ๊ฐ€ ๋ชจ๋‘ ์žˆ๋‹ค๋ฉด, ์ƒˆ๋กœ ์‹œ์ž‘ํ•ด์•ผ ํ•˜๋Š” ๊ณผ์ œ๋ถ€ํ„ฐ ์ง„ํ–‰ํ•ฉ๋‹ˆ๋‹ค.
  • ๋ฉˆ์ถฐ๋‘” ๊ณผ์ œ๊ฐ€ ์—ฌ๋Ÿฌ ๊ฐœ์ผ ๊ฒฝ์šฐ, ๊ฐ€์žฅ ์ตœ๊ทผ์— ๋ฉˆ์ถ˜ ๊ณผ์ œ๋ถ€ํ„ฐ ์‹œ์ž‘ํ•ฉ๋‹ˆ๋‹ค.

 

๊ณผ์ œ ๊ณ„ํš์„ ๋‹ด์€ ์ด์ฐจ์› ๋ฌธ์ž์—ด ๋ฐฐ์—ด plans๊ฐ€ ๋งค๊ฐœ๋ณ€์ˆ˜๋กœ ์ฃผ์–ด์งˆ ๋•Œ, ๊ณผ์ œ๋ฅผ ๋๋‚ธ ์ˆœ์„œ๋Œ€๋กœ ์ด๋ฆ„์„ ๋ฐฐ์—ด์— ๋‹ด์•„ return ํ•˜๋Š” solution ํ•จ์ˆ˜๋ฅผ ์™„์„ฑํ•ด์ฃผ์„ธ์š”.


์ œํ•œ์‚ฌํ•ญ

  • 3 ≤ plans์˜ ๊ธธ์ด ≤ 1,000
    • plans์˜ ์›์†Œ๋Š” [name, start, playtime]์˜ ๊ตฌ์กฐ๋กœ ์ด๋ฃจ์–ด์ ธ ์žˆ์Šต๋‹ˆ๋‹ค.
      • name : ๊ณผ์ œ์˜ ์ด๋ฆ„์„ ์˜๋ฏธํ•ฉ๋‹ˆ๋‹ค.
        • 2 ≤ name์˜ ๊ธธ์ด ≤ 10
        • name์€ ์•ŒํŒŒ๋ฒณ ์†Œ๋ฌธ์ž๋กœ๋งŒ ์ด๋ฃจ์–ด์ ธ ์žˆ์Šต๋‹ˆ๋‹ค.
        • name์ด ์ค‘๋ณต๋˜๋Š” ์›์†Œ๋Š” ์—†์Šต๋‹ˆ๋‹ค.
      • start : ๊ณผ์ œ์˜ ์‹œ์ž‘ ์‹œ๊ฐ์„ ๋‚˜ํƒ€๋ƒ…๋‹ˆ๋‹ค.
        • "hh:mm"์˜ ํ˜•ํƒœ๋กœ "00:00" ~ "23:59" ์‚ฌ์ด์˜ ์‹œ๊ฐ„๊ฐ’๋งŒ ๋“ค์–ด๊ฐ€ ์žˆ์Šต๋‹ˆ๋‹ค.
        • ๋ชจ๋“  ๊ณผ์ œ์˜ ์‹œ์ž‘ ์‹œ๊ฐ์€ ๋‹ฌ๋ผ์„œ ๊ฒน์น  ์ผ์ด ์—†์Šต๋‹ˆ๋‹ค.
        • ๊ณผ์ œ๋Š” "00:00" ... "23:59" ์ˆœ์œผ๋กœ ์‹œ์ž‘ํ•˜๋ฉด ๋ฉ๋‹ˆ๋‹ค. ์ฆ‰, ์‹œ์™€ ๋ถ„์˜ ๊ฐ’์ด ์ž‘์„์ˆ˜๋ก ๋” ๋นจ๋ฆฌ ์‹œ์ž‘ํ•œ ๊ณผ์ œ์ž…๋‹ˆ๋‹ค.
      • playtime : ๊ณผ์ œ๋ฅผ ๋งˆ์น˜๋Š”๋ฐ ๊ฑธ๋ฆฌ๋Š” ์‹œ๊ฐ„์„ ์˜๋ฏธํ•˜๋ฉฐ, ๋‹จ์œ„๋Š” ๋ถ„์ž…๋‹ˆ๋‹ค.
        • 1 ≤ playtime ≤ 100
        • playtime์€ 0์œผ๋กœ ์‹œ์ž‘ํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค.
      • ๋ฐฐ์—ด์€ ์‹œ๊ฐ„์ˆœ์œผ๋กœ ์ •๋ ฌ๋˜์–ด ์žˆ์ง€ ์•Š์„ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
  • ์ง„ํ–‰์ค‘์ด๋˜ ๊ณผ์ œ๊ฐ€ ๋๋‚˜๋Š” ์‹œ๊ฐ๊ณผ ์ƒˆ๋กœ์šด ๊ณผ์ œ๋ฅผ ์‹œ์ž‘ํ•ด์•ผํ•˜๋Š” ์‹œ๊ฐ์ด ๊ฐ™์€ ๊ฒฝ์šฐ ์ง„ํ–‰์ค‘์ด๋˜ ๊ณผ์ œ๋Š” ๋๋‚œ ๊ฒƒ์œผ๋กœ ํŒ๋‹จํ•ฉ๋‹ˆ๋‹ค.

 


 

ํ’€์ด ๊ณผ์ •

  1. plans๋ฅผ ์‹œ์ž‘ ์‹œ๊ฐ„์„ ๊ธฐ์ค€์œผ๋กœ ์˜ค๋ฆ„์ฐจ์ˆœ ์ •๋ ฌํ•ด์ค€๋‹ค.
  2. ์‹œ๊ฐ„ ๊ณ„์‚ฐ์„ ํŽธํ•˜๊ฒŒ ํ•˜๊ธฐ ์œ„ํ•ด ์‹œ์ž‘ ์‹œ๊ฐ„์˜ hh:mm์„ ๋ถ„ ๋‹จ์œ„๋กœ ๊ณ„์‚ฐํ•ด ๊ต์ฒดํ•œ๋‹ค.
  3. plans๋ฅผ ์ˆœํšŒํ•˜๋ฉฐ ์ฐจ๋ก€๋กœ ์ข…๋ฃŒ ์‹œ๊ฐ„๊ณผ ๋‹ค์Œ ์‹œ์ž‘ ์‹œ๊ฐ„์„ ๋น„๊ตํ•œ๋‹ค.
    • ์ข…๋ฃŒ ์‹œ๊ฐ„์ด ๋‹ค์Œ ์‹œ์ž‘ ์‹œ๊ฐ„๋ณด๋‹ค ํด ๊ฒฝ์šฐ, ๊ธฐ๋‹ค๋ ค์•ผ ํ•˜๋ฏ€๋กœ wait์— ์ถ”๊ฐ€ํ•ด์ค€๋‹ค.
    • ์ข…๋ฃŒ ์‹œ๊ฐ„์ด ๋‹ค์Œ ์‹œ์ž‘ ์‹œ๊ฐ„๋ณด๋‹ค ์ž‘๊ฑฐ๋‚˜ ๊ฐ™์„ ๊ฒฝ์šฐ, answer์— ์ถ”๊ฐ€ํ•ด์ค€๋‹ค.
      • ์—ฌ์œ  ์‹œ๊ฐ„์„ ๊ตฌํ•˜๊ณ , wait์— ์ค‘๋‹จ๋œ ๊ณผ์ œ๊ฐ€ ์žˆ๊ณ  ์—ฌ์œ  ์‹œ๊ฐ„์ด 1 ์ด์ƒ์ผ ๋•Œ ๊ฐ€์žฅ ์ตœ๊ทผ์— ์ค‘๋‹จ๋œ ๊ณผ์ œ๋ฅผ ์žฌ๊ฐœํ•œ๋‹ค.
  4. ์ˆœํšŒ๊ฐ€ ๋๋‚˜๊ณ  wait์— ์ค‘๋‹จ๋œ ๊ณผ์ œ๊ฐ€ ๋‚จ์•„ ์žˆ๋‹ค๋ฉด, ๋์—์„œ๋ถ€ํ„ฐ ์ฐจ๋ก€๋กœ answer์— ์ถ”๊ฐ€ํ•ด์ค€๋‹ค.

 

 

1. ์ผ๋ถ€๋ถ„ ์˜ค๋‹ต

def solution(plans):
    answer = []
    wait = []

    plans.sort(key=lambda x: x[1])

    for p in plans:
        sub, start_time, play = p
        # hh:mm => ๋ถ„ ๋‹จ์œ„๋กœ ๋ฐ”๊ฟ”์ฃผ๊ธฐ
        hour, minute = map(int, start_time.split(":"))
        cal_time = hour * 60 + minute
        p[1] = cal_time
        p[2] = int(p[2])

    for idx in range(len(plans)):
        # ์ข…๋ฃŒ ์‹œ๊ฐ„ ๊ตฌํ•˜๊ธฐ
        total = plans[idx][1] + plans[idx][2]
        if idx + 1 < len(plans):
            # ๋‹ค์Œ ์‹œ์ž‘ ์‹œ๊ฐ„
            next_value = plans[idx + 1][1]
            # ์ข…๋ฃŒ ์‹œ๊ฐ„ > ๋‹ค์Œ ์‹œ์ž‘ ์‹œ๊ฐ„ => ๊ธฐ๋‹ค๋ ค์•ผ ํ•จ
            if total > next_value:
                # wait์— ์ถ”๊ฐ€
                wait.append([idx, plans[idx][0]])
                # play_time ์ค„์—ฌ์ฃผ๊ธฐ
                plans[idx][2] -= next_value - plans[idx][1]
            else:
                # ๋๋‚ฌ์œผ๋ฏ€๋กœ answer์— ์ถ”๊ฐ€
                answer.append(plans[idx][0])
                # ๋‹ค์Œ ์‹œ์ž‘ ์‹œ๊ฐ„๊นŒ์ง€ ๋‚จ์€ ์—ฌ์œ ์‹œ๊ฐ„
                left = next_value - total
                # ๊ธฐ๋‹ค๋ฆฌ๊ณ  ์žˆ๋Š” ๊ณผ์ œ๊ฐ€ ์žˆ๊ณ , ๋‹ค์Œ ์‹œ์ž‘ ์‹œ๊ฐ„๊นŒ์ง€ 1๋ถ„ ์ด์ƒ ๋‚จ์•˜๋‹ค๋ฉด
                if wait and left > 0:
                    # ๊ฐ€์žฅ ์ตœ๊ทผ ๋Œ€๊ธฐํ•œ ๊ณผ์ œ
                    item = wait[-1]
                    # ์ค„์ผ ์ˆ˜ ์žˆ๋Š” ์‹œ๊ฐ„ ๊ณ„์‚ฐ
                    reduce_playtime = plans[item[0]][2] - left
                    # ์—ฌ์œ  ์‹œ๊ฐ„ ๋‚ด์— ๊ณผ์ œ๋ฅผ ๋ชจ๋‘ ๋๋‚ด์ง€ ๋ชปํ–ˆ๋‹ค๋ฉด ๋‚จ์€ ์‹œ๊ฐ„ ๊ฐฑ์‹ 
                    if reduce_playtime > 0:
                        plans[item[0]][2] = reduce_playtime
                    else:
                        # ๋‹ค ๋๋ƒˆ์œผ๋ฉด answer์— ์ถ”๊ฐ€
                        wait.pop()
                        answer.append(item[1])
        else:
            answer.append(plans[idx][0])

    # ๋‚จ์€ ๋Œ€๊ธฐ ์ค‘์ธ ๊ณผ์ œ๋“ค => ๋’ค์—์„œ๋ถ€ํ„ฐ answer์— ๋„ฃ์–ด์ฃผ๊ธฐ(๊ฐ€์žฅ ์ตœ๊ทผ์— ๋“ค์–ด์˜ด => ๋จผ์ € ๋‚˜๊ฐ)
    for item in wait[::-1]:
        answer.append(item[1])

    return answer

- 4, 5, 6, 8, 9, 10๋ฒˆ ํ…Œ์ŠคํŠธ์—์„œ ์‹คํŒจ๊ฐ€ ๋–ด๋‹ค.

- ์›์ธ์„ ์•Œ ์ˆ˜ ์—†์–ด์„œ ๊ฝค ์˜ค๋ž˜ ๊ณ ๋ฏผํ–ˆ๋Š”๋ฐ, ์—ฌ์œ ์‹œ๊ฐ„ ๋‚ด์— ์ฒ˜๋ฆฌํ•  ์ˆ˜ ์žˆ๋Š” ์ค‘๋‹จ๋œ ๊ณผ์ œ๊ฐ€ 1๊ฐœ ์ด์ƒ์ด๋ผ๋Š” ์ ์„ ๊ณ ๋ คํ•˜์ง€ ๋ชปํ–ˆ๊ธฐ ๋•Œ๋ฌธ์ด์—ˆ๋‹ค.

- ๋”ฐ๋ผ์„œ ์•„๋ž˜์™€ ๊ฐ™์ด ์—ฌ์œ ์‹œ๊ฐ„์ด ์ƒ๊ธด๋‹ค๋ฉด, while๋ฌธ์„ ํ†ตํ•ด ์ตœ๋Œ€ํ•œ ์ค‘๋‹จ๋œ ๊ณผ์ œ๋ฅผ ํ•ด๊ฒฐํ•˜๋Š” ๋ฐฉ์‹์œผ๋กœ ์ฝ”๋“œ๋ฅผ ์ˆ˜์ •ํ–ˆ๋‹ค.

 

2. ๋Ÿฐํƒ€์ž„ ์—๋Ÿฌ

def solution(plans):
    answer = []
    wait = []

    plans.sort(key=lambda x: x[1])

    for p in plans:
        sub, start_time, play = p
        # hh:mm => ๋ถ„ ๋‹จ์œ„๋กœ ๋ฐ”๊ฟ”์ฃผ๊ธฐ
        hour, minute = map(int, start_time.split(":"))
        cal_time = hour * 60 + minute
        p[1] = cal_time
        p[2] = int(p[2])

    for idx in range(len(plans)):
        # ์ข…๋ฃŒ ์‹œ๊ฐ„ ๊ตฌํ•˜๊ธฐ
        total = plans[idx][1] + plans[idx][2]
        if idx == len(plans)-1:
            answer.append(plans[idx][0])
        else:
            # ๋‹ค์Œ ์‹œ์ž‘ ์‹œ๊ฐ„
            next_value = plans[idx + 1][1]
            # ์ข…๋ฃŒ ์‹œ๊ฐ„ > ๋‹ค์Œ ์‹œ์ž‘ ์‹œ๊ฐ„ => ๊ธฐ๋‹ค๋ ค์•ผ ํ•จ
            if total > next_value:
                plans[idx][2] -= next_value - plans[idx][1]
                # wait์— ์ถ”๊ฐ€
                wait.append([plans[idx][0], plans[idx][2]])
                # play_time ์ค„์—ฌ์ฃผ๊ธฐ
            else:
                # ๋๋‚ฌ์œผ๋ฏ€๋กœ answer์— ์ถ”๊ฐ€
                answer.append(plans[idx][0])
                # ๋‹ค์Œ ์‹œ์ž‘ ์‹œ๊ฐ„๊นŒ์ง€ ๋‚จ์€ ์—ฌ์œ ์‹œ๊ฐ„
                left = next_value - total
                # ๊ธฐ๋‹ค๋ฆฌ๊ณ  ์žˆ๋Š” ๊ณผ์ œ๊ฐ€ ์žˆ๊ณ , ๋‹ค์Œ ์‹œ์ž‘ ์‹œ๊ฐ„๊นŒ์ง€ 1๋ถ„ ์ด์ƒ ๋‚จ์•˜๋‹ค๋ฉด
                if wait and left > 0:
                    for item in wait[::-1]:
                        title, playtime = item
                        if playtime <= left:
                            wa
                    while left > 0:
                        # ๊ฐ€์žฅ ์ตœ๊ทผ ๋Œ€๊ธฐํ•œ ๊ณผ์ œ
                        title, playtime = wait[-1]
                        # ์ค„์ผ ์ˆ˜ ์žˆ๋Š” ์‹œ๊ฐ„ ๊ณ„์‚ฐ
                        # ๊ฐ€์žฅ ์ตœ๊ทผ ์ค‘๋‹จํ•œ ๊ณผ์ œ๊ฐ€ ์—ฌ์œ  ์‹œ๊ฐ„ ๋‚ด์— ๋๋‚ผ ์ˆ˜ ์žˆ๋‹ค๋ฉด => answer์— ์ถ”๊ฐ€
                        if playtime <= left:
                            wait = wait[:-1]
                            answer.append(title)
                            left -= playtime
                        # ๊ฐ€์žฅ ์ตœ๊ทผ ์ค‘๋‹จํ•œ ๊ณผ์ œ๊ฐ€ ์—ฌ์œ  ์‹œ๊ฐ„ ๋‚ด์— ๋‹ค ๋๋‚ผ ์ˆ˜ ์—†๋‹ค๋ฉด => ๋‚จ์€ ์‹œ๊ฐ„ ๊ฐฑ์‹ 
                        else:
                            wait[-1][1] -= left
                            break

    # ๋‚จ์€ ๋Œ€๊ธฐ ์ค‘์ธ ๊ณผ์ œ๋“ค => ๋’ค์—์„œ๋ถ€ํ„ฐ answer์— ๋„ฃ์–ด์ฃผ๊ธฐ(๊ฐ€์žฅ ์ตœ๊ทผ์— ๋“ค์–ด์˜ด => ๋จผ์ € ๋‚˜๊ฐ)
    for item in wait[::-1]:
        answer.append(item[0])

    return answer

 

- ํ•˜์ง€๋งŒ ์ด๋ฒˆ์—” ๋Ÿฐํƒ€์ž„์—๋Ÿฌ๊ฐ€ ๋‚ฌ๋‹ค ๐Ÿฅฒ

- while๋ฌธ์„ for๋ฌธ์œผ๋กœ ๋ฐ”๊พธ์–ด ์‹คํ–‰ ์†๋„๋ฅผ ์ค„์—ฌ์ฃผ์—ˆ๋‹ค.

 

3. ์ตœ์ข… ์ •๋‹ต

def solution(plans):
    answer = []
    wait = []

    plans.sort(key=lambda x: x[1])

    for p in plans:
        sub, start_time, play = p
        # hh:mm => ๋ถ„ ๋‹จ์œ„๋กœ ๋ฐ”๊ฟ”์ฃผ๊ธฐ
        hour, minute = map(int, start_time.split(":"))
        cal_time = hour * 60 + minute
        p[1] = cal_time
        p[2] = int(p[2])

    for idx in range(len(plans)):
        # ์ข…๋ฃŒ ์‹œ๊ฐ„ ๊ตฌํ•˜๊ธฐ
        total = plans[idx][1] + plans[idx][2]
        if idx == len(plans)-1:
            answer.append(plans[idx][0])
        else:
            # ๋‹ค์Œ ์‹œ์ž‘ ์‹œ๊ฐ„
            next_value = plans[idx + 1][1]
            # ์ข…๋ฃŒ ์‹œ๊ฐ„ > ๋‹ค์Œ ์‹œ์ž‘ ์‹œ๊ฐ„ => ๊ธฐ๋‹ค๋ ค์•ผ ํ•จ
            if total > next_value:
                plans[idx][2] -= next_value - plans[idx][1]
                # wait์— ์ถ”๊ฐ€
                wait.append([plans[idx][0], plans[idx][2]])
                # play_time ์ค„์—ฌ์ฃผ๊ธฐ
            else:
                # ๋๋‚ฌ์œผ๋ฏ€๋กœ answer์— ์ถ”๊ฐ€
                answer.append(plans[idx][0])
                # ๋‹ค์Œ ์‹œ์ž‘ ์‹œ๊ฐ„๊นŒ์ง€ ๋‚จ์€ ์—ฌ์œ ์‹œ๊ฐ„
                left = next_value - total
                # ๊ธฐ๋‹ค๋ฆฌ๊ณ  ์žˆ๋Š” ๊ณผ์ œ๊ฐ€ ์žˆ๊ณ , ๋‹ค์Œ ์‹œ์ž‘ ์‹œ๊ฐ„๊นŒ์ง€ 1๋ถ„ ์ด์ƒ ๋‚จ์•˜๋‹ค๋ฉด
                if wait and left > 0:
                    temp = wait[:]
                    # ์—ฌ์œ  ์‹œ๊ฐ„ ๋‚ด์— ํ•ด๊ฒฐํ•  ์ˆ˜ ์žˆ๋Š” ๊ณผ์ œ๊ฐ€ 1๊ฐœ ์ด์ƒ์ผ ์ˆ˜๋„ ์žˆ์Œ!!
                    for idx in range(len(temp)-1, -1, -1):
                        title, playtime = temp[idx]
                        if playtime < left:
                            wait.pop(idx)
                            answer.append(title)
                            left -= playtime
                        elif playtime == left:
                            wait.pop(idx)
                            answer.append(title)
                            break
                        else:
                            wait[idx][1] -= left
                            break

    # ๋‚จ์€ ๋Œ€๊ธฐ ์ค‘์ธ ๊ณผ์ œ๋“ค => ๋’ค์—์„œ๋ถ€ํ„ฐ answer์— ๋„ฃ์–ด์ฃผ๊ธฐ(๊ฐ€์žฅ ์ตœ๊ทผ์— ๋“ค์–ด์˜ด => ๋จผ์ € ๋‚˜๊ฐ)
    for item in wait[::-1]:
        answer.append(item[0])

    return answer

- ํ†ต๊ณผ!