第3题-参加博览会
不能一个一个遍历会议,因为可能会有其他会议满足要求,所以需要统计当前天数满足要求的会议,从中选择k个
#include<bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
vector<pair<int, int>>num;
int main(){
int n, k;
cin>>n>>k;
for(int i = 0; i < n; i ++){
int u, v;
cin>>u>>v;
num.push_back({u, v});
}
sort(num.begin(), num.end());
int ans = 0, id = 0, st = 1;
priority_queue<int>q;
while(id < n || !q.empty()){
while(!q.empty() && abs(q.top()) < st){
q.pop();
}
while(id < n && num[id].first <= st){
q.push(-num[id].second);
id ++;
}
if(q.empty()){
if(id == n) break;
st = max(st, num[id].first);
}
while(id < n && num[id].first <= st){
q.push(-num[id].second);
id ++;
}
for(int i = 0; i < k; i ++){
if(!q.empty()){
ans ++;
q.pop();
}
}
st ++;
}
cout<<ans<<endl;
return 0;
}
标签:int,while,华为,num,&&,8.28,id,empty
From: https://www.cnblogs.com/voids5/p/18389059