【贪心+堆】AtCoder Grand Contest(018)C[Coins]题解
来源:互联网 发布:js思维导图插件 编辑:程序博客网 时间:2024/06/05 23:43
题目概述
有
解题报告
挺好的题目,可以完美地干翻像我这样的蒟蒻。我们先考虑只有金币和银币的最优策略:按照
如果有铜币怎么办?我们可以在原来的基础上处理。由于有了铜币,原先的方法不一定最优,但要取
示例程序
#include<cstdio>#include<algorithm>#define fr first#define sc second#define mp make_pairusing namespace std;typedef long long LL;const int maxn=100000;int X,Y,Z,n;LL ans,now,C;struct data {int a,b,c;bool operator < (const data &c) const {return b-a<c.b-c.a;}};data a[maxn+5];bool vis[maxn+5];int ss,sb,Hs[maxn+5];pair<int,int> Hb[maxn+5];#define Eoln(x) ((x)==10||(x)==13||(x)==EOF)inline char readc(){ static char buf[100000],*l=buf,*r=buf; if (l==r) r=(l=buf)+fread(buf,1,100000,stdin); if (l==r) return EOF;return *l++;}inline int readi(int &x){ int tot=0,f=1;char ch=readc(),lst='+'; while ('9'<ch||ch<'0') {if (ch==EOF) return EOF;lst=ch;ch=readc();} if (lst=='-') f=-f; while ('0'<=ch&&ch<='9') tot=(tot<<1)+(tot<<3)+ch-48,ch=readc(); return x=tot*f,Eoln(ch);}#define Push_s(x) Hs[++ss]=(x),push_heap(Hs+1,Hs+1+ss)#define Pop_s() pop_heap(Hs+1,Hs+1+ss--)#define Push_b(x,ID) Hb[++sb]=mp((x),(ID)),push_heap(Hb+1,Hb+1+sb)#define Pop_b() pop_heap(Hb+1,Hb+1+sb--)int main(){ freopen("C.in","r",stdin); freopen("C.out","w",stdout); readi(X);readi(Y);readi(Z);n=X+Y+Z; for (int i=1;i<=n;i++) readi(a[i].a),readi(a[i].b),readi(a[i].c),C+=a[i].c; sort(a+1,a+1+n);for (int i=X+1;i<=n;i++) Push_b(a[i].b-a[i].c,i); for (int i=1;i<=Y;i++) now+=Hb[1].fr,vis[Hb[1].sc]=true,Pop_b(); for (int i=1;i<=X;i++) now+=a[i].a-a[i].c,Push_s(a[i].c-a[i].a);ans=now; for (int i=X+1;i<=n-Y;i++) { if (a[i].c-a[i].a<Hs[1]) now+=(LL)Hs[1]+a[i].a-a[i].c,Pop_s(),Push_s(a[i].c-a[i].a); if (vis[i]) { while (vis[Hb[1].sc]) Pop_b();vis[Hb[1].sc]=true; now+=(LL)Hb[1].fr-a[i].b+a[i].c;Pop_b(); } vis[i]=true;ans=max(ans,now); } return printf("%lld\n",ans+C),0;}
阅读全文
0 0
- 【贪心+堆】AtCoder Grand Contest(018)C[Coins]题解
- 题解Atcoder Grand Contest C
- 【AtCoder】 Grand Contest 018 C
- AtCoder Grand Contest 012 题解
- AtCoder Grand Contest 013 题解
- 【题解】AtCoder Grand Contest 016
- Atcoder Grand Contest 19 题解
- AtCoder Grand Contest 018
- AtCoder Grand Contest 018
- AtCoder Grand Contest 014C: Closed Rooms 题解
- Atcoder Grand Contest 013C
- AtCoder Grand Contest 017 C
- AtCoder Grand Contest 019 C
- (AtCoder Grand Contest 019) C
- AtCoder Grand Contest 001 C
- AtCoder Grand Contest 018 A
- atcoder grand Contest 018 A
- AtCoder Grand Contest 018 A
- Thunderhead Engineering PetraSim
- tomcat启动如何设置127.0.0.1:8080访问网站首页
- PTA 7-9(树) 目录树(30 分) 30分代码 建树+输出
- Android开发环境
- 微信的离线交互逻辑
- 【贪心+堆】AtCoder Grand Contest(018)C[Coins]题解
- Android Beginners: NDK Setup Step by Step
- android启动时splash页出现白屏/黑屏
- JavaScript正则表达式——几个常用验证(不间断更新)
- jdbc
- 一文总结学习 Python 的 14 张思维导图
- 【POI】Apache POI工作簿(五)
- Android Studio编译报错“java.lang.OutOfMemoryError: GC overhead limit exceeded”
- 关于Java基类Object