Result: Accepted
Time: 4ms
Memory: 1144kB
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<algorithm>
using namespace std;
bool cmp(const double &a,const double &b){
return a>b;
}
double sum[1000];
int main(){
int t,x,y,n,flag,tans;
double ans,len;
scanf("%d",&t);
while(t--){
flag=0;ans=0,tans=0;
scanf("%d%d%d",&x,&y,&n);
for(int i=1;i<=n;i++){
scanf("%lf",&sum[i]);
}
sort(sum+1,sum+n+1,cmp);
for(int i=1;i<=n;i++){
if(2*sum[i]<=y) {
break;
}
tans++;
ans+=sqrt(sum[i]*sum[i]-1.0*y*y/4)*2;
if(ans>=x) {
flag=1;
break;
}
}
if(flag) {
printf("%d\n",tans);
}
else printf("-1\n");
}
}