题解
2026-06-27 11:15:57
发布于:浙江
9阅读
0回复
0点赞
用结构体存一下ti和ri,
用个bool的数组存该时间段是否被占
参考代码:
#include <bits/stdc++.h>
using namespace std;
struct GAME{
int t,r;
}a[510];
bool cmp(GAME x,GAME y){
return x.r > y.r;
}
int main(){\
int n,cnt = 0,c;
bool b[510] = {0};
cin >> n;
for (int i = 1;i <= n;i++){
cin >> a[i].t;
}
for (int i = 1;i <= n;i++){
cin >> a[i].r;
}
sort(a + 1,a + n + 1,cmp);
for (int i = 1;i <= n;i++){
if (!b[a[i].t]){
b[a[i].t] = true;
cnt += a[i].r;
//cout << cnt << " ";
}else{
c = a[i].t;
while (c >= 1){
if (!b[c]){
b[c] = true;
cnt += a[i].r;
break;
}else{
//b[a[i].t] = true;
c--;
}
}
}
}
cout << cnt;
return 0;
}
这里空空如也





有帮助,赞一个