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

 

1781번: 컵라면

상욱 조교는 동호에게 N개의 문제를 주고서, 각각의 문제를 풀었을 때 컵라면을 몇 개 줄 것인지 제시 하였다. 하지만 동호의 찌를듯한 자신감에 소심한 상욱 조교는 각각의 문제에 대해 데드라

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<intint>vector<pair<intint>>,greater<pair<int,int>>> pq;
    priority_queue<intvector<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

+ Recent posts