#6035. 「雅礼集训 2017 Day4」洗衣服
前言
这个贪心有点妙,考试的时候没有想出来,一看题解恍然大悟。
分析
首先对于洗衣服,显而易见我们可以用堆来处理,可以得出每件衣服洗完的时间
#include<bits/stdc++.h> #define N 100005 #define M 1000005 using namespace std; inline int read(){ int x=0,f=1;char ch=getchar(); while(ch<'0'||ch>'9'){if(ch=='-')f=-f;ch=getchar();} while(ch>='0'&&ch<='9'){x=(x<<1)+(x<<3)+(ch^48);ch=getchar();} return x*f; } int n,na,nb; int a[N],b[N]; long long ans,t[M],s[M]; struct node{ long long ed; int use; bool operator < (const node &A) const {return A.ed<ed;} }; priority_queue<node> q1,q2; signed main(){ // freopen("laundry.in","r",stdin); // freopen("laundry.out","w",stdout); n=read(),na=read(),nb=read(); for(int i=1;i<=na;++i) a[i]=read(),q1.push((node){a[i],a[i]}); for(int i=1;i<=nb;++i) b[i]=read(),q2.push((node){b[i],b[i]}); for(int i=1;i<=n;++i){ t[i]=q1.top().ed,q1.push((node){t[i]+q1.top().use,q1.top().use}); q1.pop(); s[i]=q2.top().ed,q2.push((node){s[i]+q2.top().use,q2.top().use}); q2.pop(); } for(int i=1;i<=n;++i) ans=max(ans,t[i]+s[n-i+1]); printf("%lld\n",ans); // fclose(stdin); // fclose(stdout); return 0; }
本文作者:南风未起
本文链接:https://www.cnblogs.com/jiangchen4122/p/16973697.html
版权声明:本作品采用知识共享署名-非商业性使用-禁止演绎 2.5 中国大陆许可协议进行许可。
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步