AcWing 1262. 鱼塘钓鱼
原题链接
简单
作者:
MrYun
,
2021-05-06 11:26:19
,
所有人可见
,
阅读 323
C++优先队列
#include <iostream>
#include <queue>
using namespace std;
struct Fish {
int num;
int d_;
Fish(int a, int b) : num(a), d_(b) {}
bool operator<(const Fish& rhs) const {
return num < rhs.num;
}
};
priority_queue<Fish> p;
const int N = 110;
int n, T;
int a[N], d[N], l[N];
int main() {
cin>>n;
for (int i = 1; i <= n; ++i) cin>>a[i];
for (int i = 1; i <= n; ++i) cin>>d[i];
for (int i = 2; i <= n; ++i) {
int x;
cin>>x;
l[i] = l[i-1] + x;
}
cin>>T;
int res = 0;
for (int i = 1; i <= n; ++i) {
int t = T - l[i], total = 0;
if (t < 0) break;
for (int j = 1; j <= i; ++j) {
p.push({a[j], d[j]});
}
while (t > 0) {
Fish f = p.top();
total += f.num;
p.push({max(0, f.num - f.d_), f.d_});
p.pop();
t--;
}
while(!p.empty()) p.pop();
res = max(res, total);
}
cout<<res<<endl;
return 0;
}