아직 만들고 있는 페이지입니다.

이 페이지는 아직 만드는 중입니다. 보이는 내용은 바뀔 수 있습니다.

King's Roads

시간 제한2초메모리 제한256 MB

요약
도시 i와 j를 잇는 도로의 비용이 a_i + a_j이고 합이 M 이상이면 M을 돌려받을 때, 모든 도시를 연결하는 최소 비용을 구한다.
난이도

보통10점 중 7점

유형
그래프, 최소 신장 트리, 그리디, 정렬
정답자
아직 제출이 없습니다

문제

King Byteasar wants to introduce an innovative road network in Byteland. There are nn cities in Byteland. There are a_ia\_i citizens living in ii-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 ii and jj costs a_i+a_ja\_i + a\_j bytalers per year. However, if a_i+a_ja\_i + a\_j is at least MM, the road is considered a national highway, and it brings revenue of MM bytalers per year from taxation (thus, the effective cost for this road is a_i+a_j−Ma\_i + a\_j - M per year). Note that all a_ia\_i are less than MM.

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 nn and MM (1≤n≤200,0001 \leq n \leq 200\\,000, 1≤M≤1091 \leq M \leq 10^9).

The second line contains nn space-separated integers a_1a\_1, …\ldots, a_na\_n (0≤a_i<M0 \leq a\_i < M).

출력

Print one integer --- the minimum annual cost for maintaining a spanning set of roads in bytalers.

예제1

  1. 예제 1

    입력
    5 9
    1 3 5 8 8
    
    예상 출력
    6