Result: Accepted
Time: 4ms
Memory: 5772kB
#include<cstring>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<string>
#include<map>
using namespace std;
const int maxn = 1010;
const int inf = 0x3f3f3f3f;
const int modu = 1e9+7;
const double PI = 3.1415926;
int n,m,k,t,sum,ans,minn;
int x,y;
double l,r,q;
int a[maxn][maxn];
double b[maxn];
map<string,int> mp;
string s[maxn];
bool cmp(double a ,double b){
return a>b;
}
int main(){
cin>>t;
while(t--){
ans=0;
cin>>n>>m>>k;
for(int i=0;i<k;i++){
cin>>b[i];
b[i]=b[i]>m*1.0/2?sqrt(b[i]*b[i]-(double)m*m/4.0):0.0;
}
sort(b,b+k,cmp);
l=n*1.0;
for(int i=0;i<k;i++){
if(b[i]==0.0) break;
l-=2*b[i];
ans++;
if(l<=0) break;
}
if(l>0) cout<<"-1"<<endl;
else cout<<ans<<endl;
}
}