code:
#include<bits/stdc++.h>
using namespace std;
int m,n,maxdis[505],f[1005],cnt,k,ans;
struct Tree{
int x,y;
}t[1005];
struct Edge{
Tree u,v;
double w;
int uid,vid;
}e[1000005];
bool cmp(Edge a,Edge b) {
return a.w<b.w;
}
int find(int x) {
return f[x]=((f[x]==x)?x:find(f[x]));
}
int main() {
cin>>m;
for(int i=1;i<=m;i++) {
cin>>maxdis[i];
}
cin>>n;
for(int i=1;i<=n;i++) {
f[i]=i;
cin>>t[i].x>>t[i].y;
}
for(int i=1;i<=n;i++) {
for(int j=1;j<=n;j++) {
if(i==j) continue;
e[++k].u=t[i],e[k].v=t[j],e[k].w=sqrt(pow(t[i].x-t[j].x,2)+pow(t[i].y-t[j].y,2)),e[k].uid=i,e[k].vid=j;
}
}
sort(e+1,e+k+1,cmp);
for(int i=1;i<=k;i++) {
int fu=find(e[i].uid),fv=find(e[i].vid);
double dis=e[i].w;
if(fu!=fv) {
f[fu]=fv;
if(++cnt==n-1) {
for(int j=1;j<=m;j++) {
if(maxdis[j]>dis) ans++;
}
cout<<ans;
return 0;
}
}
}
return 0;
}