diff --git a/백준/2206.py b/백준/2206.py new file mode 100644 index 0000000..ee8a375 --- /dev/null +++ b/백준/2206.py @@ -0,0 +1,41 @@ +import sys +from collections import deque +from collections import defaultdict + +sys.setrecursionlimit(10**6) + +input = sys.stdin.readline + +graph = defaultdict(list) + +n, m = map(int, input().split()) +arr = [] + +for i in range(n): + arr.append(list(map(int, input().strip()))) + +dist = [[[0 for _ in range(2)] for _ in range(m)] for _ in range(n)] + +dx = [0, 1, 0, -1] +dy = [1, 0, -1, 0] + +now_x, now_y = 0, 0 + +q = deque([(0, 0, False)]) +dist[0][0][0] = 1 + +while q: + x, y, jump = q.popleft() + if x == m-1 and y == n-1: + print(dist[y][x][jump]) + sys.exit(0) + for dx, dy in ((x+1, y), (x, y+1), (x-1, y), (x, y-1)): + if 0<=dx avg_lst): + tot += 1 + sum = i + else : + sum += i + + if(tot > M): # 용량을 줄여야 하는 상태 + min_lst = avg_lst + 1 + else: + result = avg_lst + max_lst = avg_lst - 1 + + +print(result) \ No newline at end of file diff --git a/백준/2696.py b/백준/2696.py new file mode 100644 index 0000000..e71fa9e --- /dev/null +++ b/백준/2696.py @@ -0,0 +1,37 @@ +import sys +import queue +from heapq import heappush, heappop + +input = sys.stdin.readline + +T = int(input()) + +for _ in range(T): + M = int(input()) + max_heap = [] + min_heap = [] + result = [] + numbers = [] + + while len(numbers) < M: + numbers.extend(list(map(int, input().split()))) + + for i in range(M): + num = numbers[i] + if(len(max_heap)<=len(min_heap)): + heappush(max_heap,-num) + else: + heappush(min_heap, num) + + if min_heap and -max_heap[0] > min_heap[0]: + temp_max = -heappop(max_heap) + temp_min = heappop(min_heap) + heappush(max_heap, -temp_min) + heappush(min_heap, temp_max) + + if (i + 1) % 2 == 1: + result.append(-max_heap[0]) + + print(len(result)) + for i in range(0, len(result), 10): + print(*result[i:i+10]) \ No newline at end of file