#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long ll;
struct node{
int a,b;
ll c;
bool operator<(const node &x) const{
return x.c<c;
}
};
vector<int> bb[100005];
priority_queue<node> q;
int h[100005],ans=0,father[100005];
int find(int x)
{
if(father[x]==x)
return x;
return father[x]=find(father[x]);
}
void unionset(int x,int y)
{
father[find(y)]=find(x);
}
bool pd[100005];
void bfs(int n)
{
queue<int> qq;
qq.push(1);
pd[1]=true;
while(!qq.empty())
{
ans++;
int top=qq.front();
for(int i=0;i<bb[top].size();i++)
{
int _=bb[top][i];
if(!pd[_])
{
qq.push(_);
pd[_]=true;
}
}
qq.pop();
}
}
int main()
{
int n,m;
scanf("%d%d",&n,&m);
for(int i=1;i<=n;i++)
{
scanf("%d",&h[i]);
father[i]=i;
}
for(int i=1;i<=m;i++)
{
int a,b;
ll c;
scanf("%d%d%llu",&a,&b,&c);
if(h[a]>h[b])
bb[a].push_back(b),q.push({a,b,c});
else if(h[a]==h[b])
bb[a].push_back(b),bb[b].push_back(a),q.push({a,b,c});
else
bb[b].push_back(a),q.push({b,a,c});
}
bfs(n);
printf("%d ",ans);
ll sum=0;
while(!q.empty())
{
int x=find(q.top().a),y=find(q.top().b);
ll z=q.top().c;
if(x!=y&&pd[x]&&pd[y])
{
unionset(x,y);
sum+=z;
}
q.pop();
}
printf("%llu",sum);
}