35分蒟蒻求助
查看原帖
35分蒟蒻求助
158878
B1ade_楼主2020/5/4 15:32
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<algorithm>
#include<iomanip>
#include<stack>
#include<queue>
#include<vector>
using namespace std;
int a[200005],b[200005],ans[200005],n;
int search(int left,int right,int x)
{
	if (left==right) return left;
	int mid=(left+right)/2;
	int s=0;
	for (int i=n;i>=n-mid+1;--i)
	{
		s+=a[i];
	}
	if (s<x)
		return search(mid+1,right,x);
	if (mid==1) return mid;
	return min(mid,search(left,mid,x));
}
int main()
{
	int l,v,sum=0;cin>>n>>l>>v;
	for (int i=1;i<=n;++i)
	{
		cin>>b[i];
		a[i]=b[i]/v;
		sum+=a[i];
	}
	sort(a+1,a+n+1);
	int p;cin>>p;
	sort(a+1,a+n+1);
	int t=0;
	for (int g=1;g<=p;++g)
	{
		int s;cin>>s;double j=l/v;
		if (j>=s)
		{
			ans[++t]=0;
			continue;
		}
		if (sum+l/v<s)
		{
			ans[++t]=-1;
			continue;
		}
		int x=s-l/v;
		ans[++t]=search(1,n,x);
	}
	for (int i=1;i<=t;++i)
		cout<<ans[i]<<endl;
	return 0;
}
2020/5/4 15:32
加载中...