목록문제 (388)
sm 기술 블로그
import java.util.*; import java.io.*; class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int N = sc.nextInt(); StringBuilder sb = new StringBuilder(); PriorityQueue leftQue = new PriorityQueue(); PriorityQueue rightQue = new PriorityQueue(); for (int i = 0; i < N; i++) { int x = sc.nextInt(); if (leftQue.size() == rightQue.size()) leftQue.add(-x); else rig..
import heapq import sys input = sys.stdin.readline N = int(input()) leftHeap = [] rightHeap = [] result = [] for i in range(N): x = int(input()) if len(leftHeap) == len(rightHeap): heapq.heappush(leftHeap, -x) else: heapq.heappush(rightHeap, x) if rightHeap and rightHeap[0] < -leftHeap[0]: leftValue = heapq.heappop(leftHeap) rigthValue = heapq.heappop(rightHeap) heapq.heappush(leftHeap, -rigthVa..
import java.util.*; import java.io.*; class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int N = sc.nextInt(); StringBuilder sb = new StringBuilder(); PriorityQueue que = new PriorityQueue(new Comparator() { public int compare(Integer i1, Integer i2) { // 절대값의 값이 같을 경우 if (Math.abs(i1) == Math.abs(i2)) { return i1 - i2; } else { return Math.abs(i1) - Math...
from queue import PriorityQueue import sys input = sys.stdin.readline N = int(input()) que = PriorityQueue(maxsize=N) result = [] for _ in range(N): X = int(input()) if(X == 0): if que.empty(): result.append("0") else: tmp = que.get() if tmp[1] 0: que.put([X, 1]) else: que.put([-X, -1]) print("\n".join(result)) 문제요약 값..