神奇RE
查看原帖
神奇RE
228788
ChangYiMing楼主2020/4/29 20:39
#include <stdio.h>
#include <algorithm>
#define ll long long
#define MAXN 200005
using namespace std;

int read(){
	int a1=0,k1=1;char c1=getchar();
	while(c1<'0'||c1>'9'){
		if(c1=='-')k1=-1;c1=getchar();
	}
	while(c1>='0'&&c1<='9'){
		a1=a1*10+c1-'0';
		c1=getchar();
	}
	return a1*k1;
}
inline void out1(ll n) {
	if(n < 0)
		putchar ('-') , n = -n;
	if(n > 9)
		out1(n / 10);
	putchar(n % 10 + '0');
}
inline void out(ll n){
	out1(n);printf("\n");
}
int magic[MAXN],f[MAXN],qu[MAXN];
int main(){
//	freopen("endless.in","r",stdin);
//	freopen("endless.out","w",stdout);
	int n=read(),l=read(),v=read(),q,sb;
	for(int i=1;i<=n;++i){
		magic[i]=read();
	}
	sort(magic+1,magic+1+n);
	q=read();
	for(int i=1;i<=q;++i){
		qu[i]=read();qu[i]*=v;
	}
	sort(qu+1,qu+1+q);f[0]=l;
	for(int i=1;i<=n;++i){
		f[i]=f[i-1]+magic[n-i+1];
		if(f[i]>qu[q])break;
	}
	for(int i=0;i<=n;++i){
		printf("%d ",f[i]);
	}
	for(int i=1,j=0;i<=q;++i){
		sb=0;
		while(qu[i]>=f[j]){
			j++;
			if(j>n)sb=1;
		}
		if(sb)printf("-1\n");
		else printf("%d\n",j);
	}
	return 0;
}

*/
注:考试中带了freopen
2020/4/29 20:39
加载中...