Result: Accepted
Time: 4ms
Memory: 79896kB
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<cstdio>
using namespace std;
typedef long long ll;
const int inf=0x3f3f3f3f;
const int maxn=1e7+100;
double a[maxn];
struct rule{
bool operator()(const double &a1,const double &a2){
return a1>a2;
}
};
int main(){
int t;
scanf("%d",&t);
while(t--){
double x,y;
int n,tot=0;
scanf("%lf %lf %d",&x,&y,&n);
for(int i=0;i<n;i++){
double k;
scanf("%lf",&k);
double f=4*k*k-y*y;
if(f<0) a[i]=0;
else a[i]=sqrt(f);
}
sort(a,a+n,rule());
for(int i=0;i<n;i++){
x-=a[i];
tot++;
if(x<=0) break;
}
if(x>0) printf("-1\n");
else printf("%d\n",tot);
}
}