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 |
Tags
- 우선순위 큐
- 트리
- 수학
- BFS
- 백준
- 자료구조
- 스택
- 투 포인터
- 시뮬레이션
- 재귀
- Unreal Engine 5
- 누적 합
- 유니온 파인드
- ue5
- DFS
- 그래프
- XR Interaction Toolkit
- 유니티
- 브루트포스
- 알고리즘
- 구현
- Team Fortress 2
- c++
- 백트래킹
- 다익스트라
- 정렬
- 그리디 알고리즘
- VR
- 다이나믹 프로그래밍
- 문자열
Archives
- Today
- Total
1일1알
백준 22252번 정보 상인 호석 C++ 본문
https://www.acmicpc.net/problem/22252
22252번: 정보 상인 호석
암흑가의 권력은 주먹과 정보에서 나온다. 주먹은 한 명에게 강하고, 정보는 세계를 가지고 놀 수 있기 때문에 호석이는 세상 모든 정보를 모으는 "정보 상인"이 되고 싶다. 정보 상인은 정보를
www.acmicpc.net
map에 key를 고릴라의 이름, value를 정보를 저장하고 있는 우선순위 큐로 넣어서 풀었다.
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <algorithm>
#include <utility>
#include <stack>
#include <queue>
#include <math.h>
#include <set>
#include <map>
#include <list>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <limits.h>
using namespace std;
using int64 = long long;
int q;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin >> q;
int64 ans = 0;
map<string, priority_queue<int>> mp;
for (int i = 0; i < q; i++) {
int type;
string name;
cin >> type >> name;
auto it = mp.find(name);
if (type == 1) {
int k;
cin >> k;
for (int i = 0; i < k; i++) {
int cost;
cin >> cost;
if (it == mp.end()) {
priority_queue<int> pq;
mp.insert({ name,pq });
}
mp[name].push(cost);
}
}
else {
int b;
cin >> b;
if (it != mp.end()) {
for (int i = 0; i < b; i++) {
if (mp[name].empty()) break;
int top = mp[name].top();
ans += top;
mp[name].pop();
}
}
}
}
cout << ans;
}
'알고리즘' 카테고리의 다른 글
백준 17390번 이건 꼭 풀어야 해! C++ (0) | 2022.11.30 |
---|---|
백준 13022번 늑대와 올바른 단어 C++ (0) | 2022.11.29 |
백준 10703번 유성 C++ (0) | 2022.11.26 |
백준 13424번 비밀 모임 C++ (0) | 2022.11.25 |
백준 10025번 게으른 백곰 C++ (0) | 2022.11.24 |