BAEKJOON ONLINE JUDGE
[백준 13904] 과제 (C++)
아무것도모르는사람
2021. 8. 27. 17:28
https://www.acmicpc.net/problem/13904
13904번: 과제
예제에서 다섯 번째, 네 번째, 두 번째, 첫 번째, 일곱 번째 과제 순으로 수행하고, 세 번째, 여섯 번째 과제를 포기하면 185점을 얻을 수 있다.
www.acmicpc.net
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
32
33
34
35
|
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
#include <utility>
#include <unordered_map>
#include <map>
#include <queue>
#include <stack>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
priority_queue<pair<int, int>, vector<pair<int, int>>,greater<pair<int,int>>> pq;
priority_queue<int, vector<int>, greater<int>> answer;
int N;
cin >> N;
for (int i = 0; i < N; i++) {
int day, cost;
cin >> day >> cost;
pq.push(make_pair(day, cost));
}
int result = 0;
while (!pq.empty()) {
answer.push(pq.top().second);
result += pq.top().second;
if (answer.size() > pq.top().first) {
result -= answer.top();
answer.pop();
}
pq.pop();
}
cout << result << endl;
}
|
cs |