fragment-header
fragment-markdown
내 블로그
설정
로그인
Atcoder Beginner Contest 419-B (C++) Get Min
최초 업로드: 2025-08-16 14:09:36
최근 수정 시간: 2025-08-16 14:10:02
게시자: rlatjwls3333
카테고리: Atcoder
조회수: 14
# B - Get Min [문제 링크](https://atcoder.jp/contests/abc419/tasks/abc419_b) ## Problem Statement There is an empty bag. You are given $Q$ queries. Process these queries in order and output the answer to each type-2 query. Each query is of one of the following types: - Type 1: Given as input in the format `1 x`. Put a ball with the integer $x$ written on it into the bag. - Type 2: Given as input in the format `2`. Pick out one ball with the minimum integer written on it from the balls in the bag, and report that integer as the answer. This query is not given when the bag contains no balls. ## Constraints - $2 \leq Q \leq 100$ - In a type-1 query, $1 \leq x \leq 100$ - When a type-2 query is given, the bag is not empty - At least one type-2 query is given - All input values are integers ## Input The input is given from Standard Input in the following format: $Q$ $query_1$ $query_2$ $\ldots$ $query_Q$ Here, $query_i$ is the $i$-th query and is given in one of the following formats: $1\ x$ $2$ ## Output Let $q$ be the number of type-2 queries, and output $q$ lines. The $i$-th line should contain the answer to the $i$-th type-2 query. ## 풀이 #### 우선순위 큐로 매번 최소 힙을 출력해주었다. ``` c++ #include<bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); int q; cin >> q; priority_queue<int, vector<int>, greater<int>> pq; while(q--) { int op; cin >> op; if(op==1) { int x; cin >> x; pq.push(x); } else { cout << pq.top() << '\n'; pq.pop(); } } } ```