※ 글쓴이는 취미로 코딩을 익혀보는 사람이라 정확하지 않은 내용을 담고 있을 수 있다 ※

 

이번에 볼 문제는 백준 6123번 문제인 Oh Those Fads이다.
문제는 아래 링크를 확인하자.

https://www.acmicpc.net/problem/6123 

 

6123번: O Those Fads

Like any other teenager, teen cows are occasionally overtaken by fads. Sometimes it's a hula hoop or a pet rock, other times it's Counterstrike, Pokemon, Rick Astley, or tribal tattoos on their udders. Mathematically, we know that a fad has an initial attr

www.acmicpc.net

매 순간 아직 유행에 참가하지 않은 소가 있고 그 중 유행에 참가하고자 하는 소가 있는 동안 해당 소를 유행에 참가시키는 것을 반복해 문제를 해결하자.

 

새로 유행에 참가할 소를 빠르게 탐색하기 위해 min heap을 활용할 수 있다.

 

아래는 제출한 소스코드이다.

#include <iostream>
#include <queue>
using namespace std;
typedef long long ll;

int N, K; ll L;
priority_queue<int, vector<int>, greater<>> pq;
int ans;

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);

	cin >> N >> L >> K;
	while (N--) {
		int x; cin >> x;
		pq.push(x);
	}

	while (!pq.empty() && pq.top() <= L) {
		ans++;
		L += K;
		pq.pop();
	}

	cout << ans;
}
728x90

'BOJ' 카테고리의 다른 글

[BOJ 2578 // C++] 빙고  (1) 2024.02.12
[BOJ 29131 // C++] Хобби  (0) 2024.02.11
[BOJ 29130 // C++] Стеллаж с книгами  (0) 2024.02.09
[BOJ 8385 // C++] ROT13  (1) 2024.02.08
[BOJ 8598 // C++] Zając  (1) 2024.02.07

+ Recent posts