King's Roads
시간 제한2초메모리 제한256 MB
도시 i와 j를 잇는 도로의 비용이 a_i + a_j이고 합이 M 이상이면 M을 돌려받을 때, 모든 도시를 연결하는 최소 비용을 구한다.
문제
King Byteasar wants to introduce an innovative road network in Byteland. There are cities in Byteland. There are citizens living in -th city.
Initially, there are no roads in Byteland. The king wants to build several roads in such a way that all cities are connected (directly or indirectly). He also wants to minimize expenses on maintaining the roads.
Naturally, if a road connects populous cities, it is used more heavily and thus is more expensive to maintain. Formally, maintaining a road between cities and costs bytalers per year. However, if is at least , the road is considered a national highway, and it brings revenue of bytalers per year from taxation (thus, the effective cost for this road is per year). Note that all are less than .
Help King Byteasar find the minimum annual cost for maintaining a set of roads so that all cities become connected.
입력
The first line of input contains two space-separated integers and (, ).
The second line contains space-separated integers , , ().
출력
Print one integer --- the minimum annual cost for maintaining a spanning set of roads in bytalers.