Recent Posts
Notice
No Rules Rules
가운데를 말해요 (feat. 백준, 1655번) 본문
728x90
반응형
가운데를 말해요
https://www.acmicpc.net/problem/1655
1655번: 가운데를 말해요
첫째 줄에는 백준이가 외치는 정수의 개수 N이 주어진다. N은 1보다 크거나 같고, 100,000보다 작거나 같은 자연수이다. 그 다음 N줄에 걸쳐서 백준이가 외치는 정수가 차례대로 주어진다. 정수는 -1
www.acmicpc.net
반응형
// woohyeon.kim
// kim519620.tistory.com
#include <iostream>
#include <queue>
#include <vector>
using namespace std;
int main() {
ios::sync_with_stdio(false), cin.tie(NULL);
register int N, arr[100000];
priority_queue<int> ans1;
priority_queue<int, vector<int>, greater<int>> ans2;
cin >> N;
for (register int i = 0, v; i < N; ++i) {
cin >> v;
if (ans1.size() > ans2.size()) ans2.push(v);
else ans1.push(v);
if (!ans1.empty() && !ans2.empty()) {
if (ans1.top() > ans2.top()) {
auto t1 = ans1.top(); ans1.pop();
auto t2 = ans2.top(); ans2.pop();
ans1.push(t2);
ans2.push(t1);
}
}
cout << ans1.top() << "\n";
}
return 0;
}
// *&)*@*
728x90
반응형
'생활 > 코테' 카테고리의 다른 글
양팔저울 (feat. 백준, 2629번) (0) | 2022.08.17 |
---|---|
행렬 곱셈 순서 (feat. 백준, 11049번) (0) | 2022.08.16 |
절댓값 힙 (feat. 백준, 11286번) (0) | 2022.08.16 |
최소 힙 (feat. 백준, 1927번) (0) | 2022.08.16 |
최대 힙 (feat. 백준, 11279번) (0) | 2022.08.16 |
Comments