diff --git "a/minjeong/Heap/2025-06-01-[PGS]-\353\224\224\354\212\244\355\201\254\354\273\250\355\212\270\353\241\244\353\237\254.py" "b/minjeong/Heap/2025-06-01-[PGS]-\353\224\224\354\212\244\355\201\254\354\273\250\355\212\270\353\241\244\353\237\254.py" new file mode 100644 index 0000000..bbc8343 --- /dev/null +++ "b/minjeong/Heap/2025-06-01-[PGS]-\353\224\224\354\212\244\355\201\254\354\273\250\355\212\270\353\241\244\353\237\254.py" @@ -0,0 +1,29 @@ +import heapq + +def solution(jobs): + jobs.sort() # 요청시간 기준 정렬 + job_len = len(jobs) + i = 0 # jobs 인덱스 + end_time = 0 # 현재 시간 + return_time = 0 # 작업 반환 시간 + count = 0 # 작업 처리한 개수 + + heap = [] + + while count < job_len: + # 현재 시간에 요청된 작업 처리 + while i < job_len and jobs[i][0] <= end_time: + heapq.heappush(heap, (jobs[i][1], jobs[i][0], i)) # 소요시간, 요청시간, 작업번호 순서 + i += 1 + + # 대기 큐에 작업이 있다면, 시간을 업데이트한다. + if len(heap) > 0: + work_time, start_time, num = heapq.heappop(heap) + end_time += work_time + return_time += end_time - start_time + count += 1 + else: + # 대기 큐가 비었다면, 다음 작업이 올 때까지 기다려야 한다. + end_time = jobs[i][0] + + return return_time // job_len \ No newline at end of file diff --git "a/minjeong/Heap/2025-06-02-[\353\260\261\354\244\200]-#14698-\354\240\204\354\203\235\355\226\210\353\215\224\353\213\210\354\212\254\353\235\274\354\236\204\354\227\260\352\265\254\354\236\220\354\230\200\353\215\230\352\261\264\354\227\220\353\214\200\355\225\230\354\227\254(Hard).py" "b/minjeong/Heap/2025-06-02-[\353\260\261\354\244\200]-#14698-\354\240\204\354\203\235\355\226\210\353\215\224\353\213\210\354\212\254\353\235\274\354\236\204\354\227\260\352\265\254\354\236\220\354\230\200\353\215\230\352\261\264\354\227\220\353\214\200\355\225\230\354\227\254(Hard).py" new file mode 100644 index 0000000..e083c75 --- /dev/null +++ "b/minjeong/Heap/2025-06-02-[\353\260\261\354\244\200]-#14698-\354\240\204\354\203\235\355\226\210\353\215\224\353\213\210\354\212\254\353\235\274\354\236\204\354\227\260\352\265\254\354\236\220\354\230\200\353\215\230\352\261\264\354\227\220\353\214\200\355\225\230\354\227\254(Hard).py" @@ -0,0 +1,21 @@ +import sys +import heapq +input = sys.stdin.readline + +T = int(input()) +for _ in range(T): + total = 1 + N = int(input()) + heap = list(map(int, input().split())) + if N == 1: + print(1) + continue + + heapq.heapify(heap) + + while len(heap) > 1: + energy = heapq.heappop(heap) * heapq.heappop(heap) + total *= energy + heapq.heappush(heap, energy) + + print(total % 1000000007) \ No newline at end of file diff --git "a/minjeong/Heap/2025-06-06-[\353\260\261\354\244\200]-#1715-\354\271\264\353\223\234\354\240\225\353\240\254\355\225\230\352\270\260.py" "b/minjeong/Heap/2025-06-06-[\353\260\261\354\244\200]-#1715-\354\271\264\353\223\234\354\240\225\353\240\254\355\225\230\352\270\260.py" new file mode 100644 index 0000000..26f3be4 --- /dev/null +++ "b/minjeong/Heap/2025-06-06-[\353\260\261\354\244\200]-#1715-\354\271\264\353\223\234\354\240\225\353\240\254\355\225\230\352\270\260.py" @@ -0,0 +1,16 @@ +import sys +import heapq +input = sys.stdin.readline + +N = int(input()) +cards = [int(input()) for _ in range(N)] +answer = 0 +heapq.heapify(cards) + +while len(cards) > 1: + a = heapq.heappop(cards) + b = heapq.heappop(cards) + answer += a + b + heapq.heappush(cards, a+b) + +print(answer) \ No newline at end of file