Skip to content

Commit 197b748

Browse files
authored
Merge pull request #1615 from AlgorithmWithGod/khj20006
[20251208] BOJ / P5 / 광부 호석 / 권혁준
2 parents 475fe9d + 1aa77d3 commit 197b748

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
```cpp
2+
#include <bits/stdc++.h>
3+
using namespace std;
4+
using ll = long long;
5+
6+
int N, C;
7+
vector<tuple<int, int, int>> arr;
8+
priority_queue<pair<int, int>> q;
9+
10+
int main(){
11+
cin.tie(0)->sync_with_stdio(0);
12+
13+
cin>>N>>C;
14+
arr.resize(N);
15+
for(auto &[x,y,v] : arr) cin>>x>>y>>v;
16+
sort(arr.begin(), arr.end());
17+
18+
ll ans = 0, cur = 0;
19+
for(int i=0;i<arr.size();) {
20+
int x = get<0>(arr[i]);
21+
while(i<arr.size() && get<0>(arr[i]) == x) {
22+
cur += get<2>(arr[i]);
23+
q.emplace(get<1>(arr[i]), get<2>(arr[i]));
24+
i++;
25+
}
26+
while(q.size() > C) {
27+
auto [y, v] = q.top(); q.pop();
28+
cur -= v;
29+
while(!q.empty() && q.top().first == y) {
30+
cur -= q.top().second;
31+
q.pop();
32+
}
33+
}
34+
ans = max(ans, cur);
35+
}
36+
37+
cout<<ans;
38+
39+
}
40+
```

0 commit comments

Comments
 (0)