File tree Expand file tree Collapse file tree 1 file changed +40
-0
lines changed
Expand file tree Collapse file tree 1 file changed +40
-0
lines changed Original file line number Diff line number Diff line change 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+ ```
You can’t perform that action at this time.
0 commit comments