3 条题解

  • 1
    @ 2023-7-23 7:44:58
    #include<bits/stdc++.h>
    using namespace std;
    long long n,q,x,y,b[100010];
    struct st{
    	long long x,y;
    }a[100010];
    int main(){
    	freopen("array.in","r",stdin);
    	freopen("array.out","w",stdout);
    	scanf("%lld%lld",&n,&q);
    	for(int i=1;i<=n;i++){
    		scanf("%lld%lld",&a[i].x,&a[i].y);
    	}
    	for(int i=1;i<=n+1;i++)b[i]=b[i-1]+a[i].x;//前缀和 
    	for(int i=1;i<=q;i++){
    		scanf("%lld",&x);
    		int p1=lower_bound(b+1,b+1+n,x)-b;
    		printf("%lld\n",a[p1].y);
    	}
    	//用前缀和加上lower_bound函数很简单 
    	return 0;
    }
    

    信息

    ID
    407
    时间
    1000ms
    内存
    256MiB
    难度
    8
    标签
    (无)
    递交数
    112
    已通过
    18
    上传者