Notice
Recent Posts
Recent Comments
Link
์ผ | ์ | ํ | ์ | ๋ชฉ | ๊ธ | ํ |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 | 29 |
30 | 31 |
Tags
- web
- ๋งต
- dynamic debugging
- CVE
- java
- thymeleaf
- ๊ทธ๋ฆฌ๋
- ์ฐ์ ์์ ํ
- error
- ์คํ
- ๋์ ํฉ
- Spring
- Reversing
- ์์ ์ ๋ ฌ
- ๋ฐ์ดํฌ์คํธ๋ผ
- ๋ฌธ์์ด
- DP
- c++
- ๋ฐฑํธ๋ํน
- ์ด๋ถ ํ์
- BFS
- ์๋ฎฌ๋ ์ด์
- ๊ตฌํ
- OS
- ๋ถํ ์ ๋ณต
- dfs
- ์ต๋จ ๊ฒฝ๋ก
- ์ฌ๊ท
- GCP
- JPA
Archives
- Today
- Total
hades
[Baekjoon] 11286๋ฒ: ์ ๋๊ฐ ํ ๋ณธ๋ฌธ
๐ฅ ๋ฌธ์
https://www.acmicpc.net/problem/11286
๐ ์ค๊ณ
์ฐ์ ์์ ํ๋ฅผ ์ฌ์ฉํ์ฌ ์ฒซ ๋ฒ์งธ ์กฐ๊ฑด์ผ๋ก ์ ๋๊ฐ์ ๋น๊ตํ๊ณ , ๋ ๋ฒ์งธ ์กฐ๊ฑด์ผ๋ก ์ ๋๊ฐ์ด ๊ฐ๋ค๋ฉด ์ค์ ๊ฐ์ ๋น๊ตํ์ฌ ์์ ๊ฒ์ด ์ฐ์ ์์๊ฐ ๋๋๋ก ํ๋ค.
๐ ํ์ด
#include <iostream>
#include <vector>
#include <queue>
using namespace std;
int n, x;
struct compare {
bool operator()(int a, int b) {
if (abs(a) > abs(b)) {
return true;
}
else if (abs(a) == abs(b)) {
return a > b;
}
else {
return false;
}
}
};
priority_queue<int, vector<int>, compare> pq;
int main(void)
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cin >> n;
for (int i = 0; i < n; i++) {
cin >> x;
if (x == 0) {
if (pq.empty()) {
cout << 0 << "\n";
}
else {
cout << pq.top() << "\n";
pq.pop();
}
}
else {
pq.push(x);
}
}
return 0;
}
๐ ๋ฉ๋ชจ
์ฐ์ ์์ ํ์ compare๋ ๊ตฌ์กฐ์ฒด๋ก ๋ง๋ค์ด์ ์ฌ์ฉํ๋ฉฐ, ๋ฐฐ์ด์์ ์ ๋ ฌํ๋ ํจ์์ ๋ฐ๋๋ก ์๊ฐํด์ผ ํ๋ค.
'๐ PS > Algorithm' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[Baekjoon] 11403๋ฒ: ๊ฒฝ๋ก ์ฐพ๊ธฐ (0) | 2024.07.25 |
---|---|
[Baekjoon] 11399๋ฒ: ATM (0) | 2024.07.24 |
[Baekjoon] 10026๋ฒ: ์ ๋ก์์ฝ (2) | 2024.07.22 |
[Baekjoon] 9095๋ฒ: 1, 2, 3 ๋ํ๊ธฐ (1) | 2024.07.20 |
[Baekjoon] 7662๋ฒ: ์ด์ค ์ฐ์ ์์ ํ (0) | 2024.07.17 |