社区讨论
求优化
P5661[CSP-J 2019] 公交换乘参与者 3已保存回复 3
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 3 条
- 当前快照
- 1 份
- 快照标识符
- @mhj1qmul
- 此快照首次捕获于
- 2025/11/03 19:18 4 个月前
- 此快照最后确认于
- 2025/11/03 19:18 4 个月前
CPP
#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
typedef long long ll;
priority_queue<pair<int,int> >q;//降序 存时间和票价
bool f[1002];
int n,ans;
int main(){
ios::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
cin >> n;
for(int i = 1;i <= n;i ++){
int op,p,t;
cin >> op >> p >> t;
if(op == 0){
q.push({-t,p});
f[p] = 1;
ans += p;
}else{
priority_queue<pair<int,int> >q2 = q;
bool pd = 1;
while(!q2.empty() and pd){
if((t + q2.top().first <= 45) and (p <= q2.top().second) and (f[q2.top().second])){
f[q2.top().second] = 0;
pd = 0;
break;
}
else q2.pop();
}
if(pd)ans += p;
}
}
cout << ans << endl;
return 0;
}
// 0 地铁 1 公交
//
回复
共 3 条回复,欢迎继续交流。
正在加载回复...