Result: Accepted
Time: 3ms
Memory: 1768kB
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <ctime>
#include <vector>
#include <set>
#include <string>
#include <map>
#include <queue>
#include <stack>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <deque>
#define clr(a,b) memset(a,b,sizeof(a))
#define ll long long
using namespace std;
const int maxn=1e2+10;
int t,n;
double x,y,a[maxn];
int main()
{
cin>>t;
while(t--)
{
cin>>x>>y>>n;
for(int i=0;i<n;i++)cin>>a[i];
sort(a,a+n);
int ans=0;
double len=0;
y/=2;
for(int i=n-1;i>=0;i--)
{
if(a[i]>y)
{
ans++;
len+=2*sqrt(1.0*(a[i]*a[i]-y*y));
if(len>=x)
{
printf("%d\n",ans);
break;
}
}
else
{
printf("-1\n");
break;
}
}
}
}