#include<bits/stdc++.h>
using namespace std;
struct node
{
int nxt,to,val;
}e[1145141];
struct edge
{
int x,y,val;
}a[1145141];
int n,m,h[1145141],cnt,vis[1145141],ans=1;
int f[1145141];
bool cmp(edge x,edge y)
{
return x.val<y.val;
}
int head[1145141*2],cnt_edge;
void add(int u,int v,int w)
{
e[++cnt_edge].to=v;
e[cnt_edge].val=w;
e[cnt_edge].nxt=head[u];
head[u]=cnt_edge;
}
int find(int x)
{
if(f[x]==x)
return x;
return f[x]=find(f[x]);
}
void bfs()
{
queue<int>q;
q.push(1);
vis[1]=1;
while(!q.empty())
{
int u=q.front();
q.pop();
for(int i=head[u];i;i=e[i].nxt)
{
int v=e[i].to;
a[++cnt]={u,v,e[i].val};
if(!vis[v])
{
q.push(v);
++ans;
vis[v]=1;
}
}
}
}
int main()
{
cin>>n>>m;
for(int i=1;i<=n;i++)
cin>>h[i],f[i]=i;
for(int i=1;i<=m;i++)
{
int u,v,w;
cin>>u>>v>>w;
if(h[u]>=h[v])
add(u,v,w);
if(h[u]<=h[v])
add(v,u,w);
}
bfs();
sort(a+1,a+cnt+1,cmp);
cout<<ans<<" ";
int sum=0;
for(int i=1;i<=cnt;i++)
{
// cout<<a[i].x<<" "<<a[i].y<<" "<<a[i].val<<endl;
int fx=find(a[i].x),fy=find(a[i].y);
if(fx==fy)
continue;
f[fx]=fy;
sum+=a[i].val;
}
cout<<sum;
}