diff --git "a/INSEA-99/week06/11279_\354\265\234\353\214\200_\355\236\231.py" "b/INSEA-99/week06/11279_\354\265\234\353\214\200_\355\236\231.py" new file mode 100644 index 0000000..01338eb --- /dev/null +++ "b/INSEA-99/week06/11279_\354\265\234\353\214\200_\355\236\231.py" @@ -0,0 +1,13 @@ +# pypy3 +# 시간(ms) : 164 +# 공간(KB) : 10604 + +import sys +import heapq +input = sys.stdin.readline + +pq = [] +for _ in range(int(input().strip())) : + x = int(input().strip()) + if x : heapq.heappush(pq, -x) # 0이 아닌 경우 추가 + else : print(-heapq.heappop(pq) if len(pq) else 0) # 0인 경우 길이가 0이 아니면 pop, 맞다면 0 출력 \ No newline at end of file diff --git "a/INSEA-99/week06/11286_\354\240\210\353\214\223\352\260\222_\355\236\231.py" "b/INSEA-99/week06/11286_\354\240\210\353\214\223\352\260\222_\355\236\231.py" new file mode 100644 index 0000000..b134564 --- /dev/null +++ "b/INSEA-99/week06/11286_\354\240\210\353\214\223\352\260\222_\355\236\231.py" @@ -0,0 +1,13 @@ +# pypy3 +# 시간(ms) : 180 +# 공간(KB) : 115988 + +import sys +import heapq +input = sys.stdin.readline + +pq = [] +for _ in range(int(input().strip())) : + x = int(input().strip()) + if x : heapq.heappush(pq, (abs(x), x)) # 0이 아닌 경우 추가 + else : print(heapq.heappop(pq)[1] if len(pq) else 0) # 0인 경우 길이가 0이 아니면 pop, 맞다면 0 출력 \ No newline at end of file diff --git "a/INSEA-99/week06/1927_\354\265\234\354\206\214_\355\236\231.py" "b/INSEA-99/week06/1927_\354\265\234\354\206\214_\355\236\231.py" new file mode 100644 index 0000000..e26effb --- /dev/null +++ "b/INSEA-99/week06/1927_\354\265\234\354\206\214_\355\236\231.py" @@ -0,0 +1,13 @@ +# pypy3 +# 시간(ms) : 164 +# 공간(KB) : 114132 + +import sys +import heapq +input = sys.stdin.readline + +pq = [] +for _ in range(int(input().strip())) : + x = int(input().strip()) + if x : heapq.heappush(pq, x) # 0이 아닌 경우 추가 + else : print(heapq.heappop(pq) if len(pq) else 0) # 0인 경우 길이가 0이 아니면 pop, 맞다면 0 출력 \ No newline at end of file diff --git "a/INSEA-99/week06/2075_N\353\262\210\354\247\270_\355\201\260_\354\210\230.py" "b/INSEA-99/week06/2075_N\353\262\210\354\247\270_\355\201\260_\354\210\230.py" new file mode 100644 index 0000000..2b48520 --- /dev/null +++ "b/INSEA-99/week06/2075_N\353\262\210\354\247\270_\355\201\260_\354\210\230.py" @@ -0,0 +1,21 @@ +# pypy3 +# 시간(ms) : 1028 +# 공간(KB) : 122816 +# +# 공유 : +# - int(1_000_000_000)은 약 29바이트 +# - 1500개 -> 약 0.05 MB +# - 1500*1500개 -> 약 77 MB + + +import sys +import heapq +input = sys.stdin.readline + +pq = [] +n = int(input().strip()) +for _ in range(n): + for x in list(map(int, input().strip().split())) : + if len(pq) < n : heapq.heappush(pq, x) # 리스트가 n개 이하면 추가 + else : heapq.heappush(pq, max(x, heapq.heappop(pq))) # 리스트가 n개 이상이면 리스트의 가장 작은 값보다 크다면 추가 +print(heapq.nsmallest(1, pq)[0])