BZOJ 4800 Ice Hockey World Championship
Posted on 2017-03-30 14:35 ziliuziliu 阅读(237) 评论(0) 编辑 收藏 举报折半。用一边的去查另一边。
不知不觉500了啊。。。
#include<iostream> #include<cstdio> #include<cstdio> #include<algorithm> #define maxs 1500050 #define maxn 45 using namespace std; long long n,m,p[maxn],tab[2][maxs],ans=0,n1; void dfs(long long now,long long top,long long ret,long long type) { if (now==top) { tab[type][++tab[type][0]]=ret; return; } dfs(now+1,top,ret+p[now],type); dfs(now+1,top,ret,type); } int main() { scanf("%lld%lld",&n,&m); for (long long i=1;i<=n;i++) scanf("%lld",&p[i]); if (n<=1) {printf("%lld\n",(p[1]<=m)+1LL);return 0;} n1=n>>1; dfs(1,n1+1,0,0);dfs(n1+1,n+1,0,1); sort(tab[0]+1,tab[0]+tab[0][0]+1); sort(tab[1]+1,tab[1]+tab[1][0]+1); for (long long i=1;i<=tab[0][0];i++) { long long l=1,r=tab[1][0],ret=0; while (l<=r) { long long mid=(l+r)>>1; if (tab[1][mid]<=m-tab[0][i]) {ret=mid;l=mid+1;} else r=mid-1; } ans+=ret; } printf("%lld\n",ans); return 0; }