[杂题] Codeforces 799E Round #413 E. Aquarium decoration
来源:互联网 发布:上海美工 编辑:程序博客网 时间:2024/06/05 21:08
枚举下选了几个ab都喜欢的 没什么难度 就是细节贼多
#include<cstdio>#include<cstdlib>#include<algorithm>using namespace std;typedef long long ll;inline char nc(){ static char buf[100000],*p1=buf,*p2=buf; return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;}inline void read(int &x){ char c=nc(),b=1; for (;!(c>='0' && c<='9');c=nc()) if (c=='-') b=-1; for (x=0;c>='0' && c<='9';x=x*10+c-'0',c=nc()); x*=b;}const int N=200005;int n,m,K,w[N],idx[N],back[N];ll cnt[N],sum[N];inline void add(int x,int r){ for (int i=x;i<=n;i+=i&-i) cnt[i]++,sum[i]+=r;}inline ll query(ll *c,int x){ ll ret=0; for (int i=x;i;i-=i&-i) ret+=c[i]; return ret;}inline ll Query(int k){ int L=0,R=n+1,MID; while (L+1<R) if (query(cnt,MID=(L+R)>>1)<=k) L=MID; else R=MID; return query(sum,L);}bool cmp(int x,int y){ return w[x]<w[y];}int sx[N],icnt;int a[N],b[N],c[N],d[N];ll suma[N],sumb[N],sumc[N];int la[N],lb[N];ll ans=1LL<<60;int main(){ int x,k; freopen("t.in","r",stdin); freopen("t.out","w",stdout); read(n); read(m); read(K); if (K>m) return printf("-1\n"),0; for (int i=1;i<=n;i++) read(w[i]),idx[i]=i; sort(idx+1,idx+n+1,cmp); for (int i=1;i<=n;i++) back[idx[i]]=i; read(x); if (x<K) return printf("-1\n"),0; while (x--) read(k),la[k]=1; read(x); if (x<K) return printf("-1\n"),0; while (x--) read(k),lb[k]=1; for (int i=1;i<=n;i++) if (la[i] && lb[i]) c[++*c]=i; else if (la[i]) a[++*a]=i; else if (lb[i]) b[++*b]=i; else d[++*d]=i; if (*c+(K-*c)*2>m) return printf("-1\n"),0; for (int i=1;i<=*d;i++) add(back[d[i]],w[d[i]]); sort(a+1,a+*a+1,cmp); for (int i=1;i<=*a;i++) suma[i]=suma[i-1]+w[a[i]]; sort(b+1,b+*b+1,cmp); for (int i=1;i<=*b;i++) sumb[i]=sumb[i-1]+w[b[i]]; sort(c+1,c+*c+1,cmp); for (int i=1;i<=*c;i++) sumc[i]=sumc[i-1]+w[c[i]]; int C=max(m-*a-*b-*d,max(max(K-*a,K-*b),2*K-m)); C=max(C,0); int pnt1=*a,pnt2=*b; while (pnt1>0 && pnt1>=K-C+1) add(back[a[pnt1]],w[a[pnt1]]),pnt1--; while (pnt2>0 && pnt2>=K-C+1) add(back[b[pnt2]],w[b[pnt2]]),pnt2--; ll ret=sumc[C]+suma[max(K-C,0)]+sumb[max(K-C,0)]+Query(m-(C+max(K-C,0)*2)); ans=min(ans,ret); for (C++;C<=min(m,*c);C++){ while (pnt1>0 && pnt1>=K-C+1) add(back[a[pnt1]],w[a[pnt1]]),pnt1--; while (pnt2>0 && pnt2>=K-C+1) add(back[b[pnt2]],w[b[pnt2]]),pnt2--; ret=sumc[C]+suma[max(K-C,0)]+sumb[max(K-C,0)]+Query(m-(C+max(K-C,0)*2)); ans=min(ans,ret); } printf("%I64d\n",ans); return 0;}
阅读全文
0 0
- [杂题] Codeforces 799E Round #413 E. Aquarium decoration
- codeforces round#177 E
- Codeforces Round#260E
- [博弈 杂题] Codeforces 794E Round #414 E. Choosing Carrot
- Codeforces Round #116 E-Cubes 180E
- Codeforces Round#99 E(Div2)
- codeforces div2 round#230 E
- E. Pillars(Codeforces Round #271)
- codeforces Round #344 A~E
- codeforces Round 377 Div2 E
- Educational Codeforces Round 21E
- Educational Codeforces Round 26 E
- Codeforces Beta Round #5 E
- Codeforces Round #436 E. Fire
- Educational Codeforces Round 903E
- codeforces799E Aquarium decoration
- Codeforces 405E Codeforces Round #238 (Div. 2)E
- 【Codeforces Round #185】Codeforces 311E Biologist
- ffmpeg之rtmp分析(一)
- P2870 (poj 3617) [USACO07DEC]最佳牛线,黄金Best Cow Line, Gold 可爱的贪心
- rtmp协议整理
- [最短路 杂题] Codeforces 806D VK Cup 2017 Round 3 D. Perishable Roads
- [线段树 杂题] Codeforces 806E VK Cup 2017 Round 3 E. Blog Post Rating
- [杂题] Codeforces 799E Round #413 E. Aquarium decoration
- Qt简单知识点
- [随机 Hash] Codeforces 799F Round #413 F. Beautiful fountains rows
- 我的课程与服务
- OAUTH2.0
- 求联通块周长
- 图论(八)最小生成树
- 对绝对地址赋值的问题
- dubbo的配置及使用