题解:
先把询问排序
然后根据单调性来做
代码:
#include<bits/stdc++.h> using namespace std; int n,m,a[50005],b[50005],f[50005],ans[50005]; int cmp(int x,int y) { return b[x]<b[y]; } int main() { scanf("%d%d",&n,&m); int num=0,j=1; for (int i=1;i<=n;i++)scanf("%d",&a[i]); for (int i=1;i<=m;i++)scanf("%d",&b[i]),f[i]=i; sort(f+1,f+m+1,cmp); for (int i=1;i<=m;i++) { while (a[j]+num<=b[f[i]])num+=a[j],j++; ans[f[i]]=j; } for (int i=1;i<=m;i++)printf("%d ",ans[i]); }