-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- 체커 문제: https://www.acmicpc.net/problem/1090 - 이중우선순위큐 문제: https://school.programmers.co.kr/learn/courses/30/lessons/42628
- Loading branch information
Showing
2 changed files
with
55 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
n = int(input()) | ||
coords = [] | ||
coords_x = [] | ||
coords_y = [] | ||
answer = [-1] * n | ||
|
||
for _ in range(n): | ||
x, y = map(int, input().split()) | ||
coords.append((x, y)) | ||
coords_x.append(x) | ||
coords_y.append(y) | ||
|
||
# 만날 장소 정하기 | ||
for y in coords_y: | ||
for x in coords_x: | ||
dist = [] | ||
|
||
# 각 좌표에서 만날 장소로 오는 비용 계산하기 | ||
for ex, ey in coords: | ||
d = abs(ex - x) + abs(ey - y) | ||
dist.append(d) | ||
|
||
# 가까운 순서대로 정렬 | ||
dist.sort() | ||
tmp = 0 | ||
for i in range(len(dist)): | ||
d = dist[i] | ||
tmp += d | ||
if answer[i] == -1: | ||
answer[i] = tmp | ||
else: | ||
answer[i] = min(tmp, answer[i]) | ||
|
||
print(*answer) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import heapq | ||
|
||
def solution(operations): | ||
queue = [] | ||
for i in operations: | ||
operator, num = i.split() | ||
num = int(num) | ||
|
||
if operator == 'I': | ||
heapq.heappush(queue, num) | ||
elif operator == 'D' and num == -1: | ||
if queue: | ||
heapq.heappop(queue) | ||
else: | ||
if queue: | ||
queue.remove(max(queue)) | ||
|
||
if queue: | ||
return [max(queue), heapq.heappop(queue)] | ||
else: | ||
return [0, 0] |