For each offered extra road between two houses, compute the shortest walk from house 0 that visits every house and traverses the new road fully, then print the minimum over all offers.
Medium6MathGreedySimulationImplementationNo attempts yetTime limit1sMemory limit128 MBDing dong~
"Who is it?"
"Chicken delivery."
"What? I never ordered chicken... aaargh!"
Inho hands out chicken to customers who never ordered any, so he is a good clerk. He walks along one straight street and gives the customers their chicken house by house.
One day another house joined his delivery list. To bring chicken to the new customer, Inho wants to build exactly one new road. Each of his friends told him about one road that friend is able to build.

Inho calls the chicken shop house 0, then numbers the houses 1, 2, and so on up to house n in order of distance from the shop. The road built by friend j connects house Aj and house Bj, and its length is Cj. The new house sits on that road.
Inho starts at house 0 and has to deliver chicken to every house from 1 to n and to the new house. He walks under these rules.
Find the smallest distance Inho walks when one of the roads his friends offered is built.
The first line contains n, the number of houses Inho already delivered to, and m, the number of friends who can build a road.
The second line contains the distance Li from house i−1 to house i, for i=1,2,…,n in this order.
Each of the next m lines contains Aj Bj Cj, the road that friend j can build. The road connects house Aj and house Bj and its length is Cj. Aj and Bj are always different.
1≤n,m≤10000, 1≤Li≤100, 1≤Aj,Bj≤n, 1≤Cj≤100
Print on one line the smallest distance Inho walks to deliver chicken to every house after one new road is built.


In the first example, building the second road, the road of length 5 between house 3 and house 6, and moving in the order 0, 1, 2, 3, new house, 6, 5, 4 finishes the deliveries after walking 25. Building the first road costs 32.