优先队列+贪心
2026-02-02 15:49:47
发布于:广东
31阅读
0回复
0点赞
逆序,看那个可选的游戏分值最高,该时间段选哪个,优先队列维护当前最优选择,所有最优时间段就是整体最优,以下为代码:
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
int n,cnt;
priority_queue<int,vector<int>>qq;
bool mark[502];
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
cin>>n;
int t[n];
int r[n];
for(int i=0;i<n;i++){
cin>>t[i];
}for(int i=0;i<n;i++){
cin>>r[i];
}
for(int i=n;i>=1;i--){
for(int j=0;j<n;j++){
if(t[j]>=i and !mark[j]){
qq.push(r[j]);
mark[j]=1;
}
}
if(!qq.empty()){
cnt+=qq.top();
qq.pop();
}
}
cout<<cnt;
return 0;
}
这里空空如也





有帮助,赞一个