#include<cstdio>
#include<queue>
#include<cstring>
#include<iostream>
#include<algorithm>
#define N 100001
#define M 1000001
using namespace std;
queue<int>q;
int n,m,sum;
long long ans;
int h[N],fa[N];
int to[M*2],next[M*2],tot,front[N],cnt;
bool v[N];
int a[M],b[M],len[M];
struct node
{
int u,v,w;
}e[M*2];
int read()
{
char c=getchar();int x=0;
while(c<‘0‘||c>‘9‘) c=getchar();
while(c>=‘0‘&&c<=‘9‘) {x=x*10+c-‘0‘;c=getchar();}
return x;
}
void add(int u,int v,int w)
{
to[++tot]=v; next[tot]=front[u]; front[u]=tot;
}
void bfs1()
{
q.push(1);sum=1;
v[1]=true;
int now;
while(!q.empty())
{
now=q.front();q.pop();
for(int i=front[now];i;i=next[i])
{
if(!v[to[i]])
{
v[to[i]]=true;
q.push(to[i]);
sum++;
}
}
}
}
bool cmp(node aa,node bb)
{
if(h[aa.v]!=h[bb.v]) return h[aa.v]>h[bb.v];
return aa.w<bb.w;
}
int find(int i) {return fa[i]==i ? i : fa[i]=find(fa[i]);}
void solve()
{
for(int i=1;i<=m;i++)
{
if(!v[a[i]]||!v[b[i]]) continue;
if(h[a[i]]>=h[b[i]])
{
e[++cnt].u=a[i]; e[cnt].v=b[i]; e[cnt].w=len[i];
}
if(h[b[i]]>=h[a[i]])
{
e[++cnt].u=b[i]; e[cnt].v=a[i]; e[cnt].w=len[i];
}
}
sort(e+1,e+cnt+1,cmp);
int s=0,i=1,r1,r2;
while(s<sum-1)
{
r1=find(e[i].u);
r2=find(e[i].v);
if(r1!=r2)
{
ans+=e[i].w;
fa[r1]=r2;
s++;
}
i++;
}
}
int main()
{
/*freopen("ski.in","r",stdin);
freopen("ski.out","w",stdout);*/
n=read(); m=read();
for(int i=1;i<=n;i++) h[i]=read(),fa[i]=i;
int x,y,z;
for(int i=1;i<=m;i++)
{
x=read(); y=read(); z=read();
a[i]=x; b[i]=y; len[i]=z;
if(h[x]>=h[y]) add(x,y,z);
if(h[y]>=h[x]) add(y,x,z);
}
bfs1();
printf("%d ",sum);
solve();
cout<<ans;
}