1373:鱼塘钓鱼

【题目链接】

    http://ybt.ssoier.cn:8088/problem_show.php?pid=1373

【算法】

    枚举最后一个到达的鱼塘,用堆贪心的在时间限制内取鱼。

【代码】

    

 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 int n,i,j,T,ans;
 4 int a[110],d[110],t[110];
 5 int main()
 6 {
 7     scanf("%d",&n);
 8     for(i=1;i<=n;i++) scanf("%d",&a[i]);
 9     for(i=1;i<=n;i++) scanf("%d",&d[i]);
10     for(i=2;i<=n;i++) scanf("%d",&t[i]), t[i]+=t[i-1];
11     scanf("%d",&T);
12     for(i=1;i<=n&&t[i]<=T;i++) {
13         priority_queue< pair<int,int> > heap;
14         int cur=T-t[i],tmp=0;
15         for(j=1;j<=i;j++) heap.push(make_pair(a[j],d[j]));
16         while(cur--&&heap.top().first>0) {
17             pair<int,int> p=heap.top(); heap.pop();
18             tmp+=p.first;
19             p.first-=p.second;
20             heap.push(p);
21         }
22         ans=max(ans,tmp);
23     }
24     printf("%d\n",ans);
25     return 0;
26 }

猜你喜欢

转载自www.cnblogs.com/Willendless/p/9418034.html