-
[13904] 과제BOJ 2022. 2. 25. 09:10
https://www.acmicpc.net/problem/13904
13904번: 과제
예제에서 다섯 번째, 네 번째, 두 번째, 첫 번째, 일곱 번째 과제 순으로 수행하고, 세 번째, 여섯 번째 과제를 포기하면 185점을 얻을 수 있다.
www.acmicpc.net
vector<pi>에 입력된 것을 정렬한 뒤에, 일단 큐에 넣는다.
v[i].first보다 큐의 size가 더 크다면, 현재까지 선택한 과제중 가장 점수가 낮을것을 포기한다.
#include <bits/stdc++.h>using namespace std;#ifdef ONLINE_JUDGEconstexpr bool local = false;#elseconstexpr bool local = true;#endifusing ll = long long;using pi = pair<int, int>;vector<pi> v;priority_queue<int, vector<int>, greater<int>> q;int n, ans;int main(void) {if (!local) ios_base::sync_with_stdio(0), cin.tie(0);cin >> n;v.resize(n);int i;for (i = 0; i < n; i++) cin >> v[i].first >> v[i].second;sort(v.begin(), v.end());for (i = 0; i < n; i++) {q.push(v[i].second);if (v[i].first < (int)q.size()) q.pop();}while (!q.empty()) {ans += q.top();q.pop();}cout << ans;return 0;}
ㅐ
'BOJ' 카테고리의 다른 글
[6359] 만취한 상범 (0) 2022.02.26 [1727] 커플 만들기 (0) 2022.02.25 [1455] 뒤집기 II (0) 2022.02.24 [16120] PPAP (0) 2022.02.24 [3991] 한번 쏘면 멈출 수 없어 (0) 2022.02.23