BZOJ 3391: [Usaco2004 Dec]Tree Cutting网络破坏(搜索)
这道直接遍历一遍求出每个点的子节点数目就行了= =
CODE:
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
#define maxn 50010
int b[maxn],q[maxn],id[maxn],ans[maxn];
bool cmp(int x,int y){return q[x]<q[y];}
int main(){
int n,Q;
scanf("%d%d",&n,&Q);
for (int i=1;i<=n;i++) scanf("%d",b+i);
for (int i=1;i<=Q;i++) scanf("%d",q+i);
for (int i=1;i<=Q;i++) id[i]=i;
sort(id+1,id+1+Q,cmp);
int h=1,t=0;
for (int i=1;i<=n;i++) {
t+=b[i];
while (q[id[h]]<t&&h<=Q) ans[id[h++]]=i;
}
for (int i=1;i<=Q;i++) printf("%d\n",ans[i]);
return 0;
}