Computer Network
면접 대비시간 제한2초메모리 제한1024 MB
각 컴퓨터의 선을 허브나 다른 컴퓨터에 연결해 모든 컴퓨터가 허브에 도달하도록 하면서 지연 시간 합을 최소화한다.
문제
Cupa is building a connected network using computers and a single hub.
The computers are numbered from to . Each computer has an outgoing wire that can transfer one bit of data to the other end in milliseconds.
The hub has ports into which the computer's wires can be connected, and each computer has a single port.
Cupa requires each computer's wire to be connected to some port --- either in the hub or in another computer. It should also be possible to send data to the hub from every computer, either directly or via other computers.
The network latency for each computer is defined as the time it takes to send one bit of data from computer to the hub. We will assume that it takes no time for intermediate computers to redirect received data to their own outgoing wires.
After the network is built, Cupa will calculate the network latency for each computer . He wants the total network latency over all computers, i.e. , to be as small as possible.
Help Cupa to build the network in a way that minimizes the total network latency.
입력
The first line contains two integers and --- the number of computers and the number of ports in the hub ().
The second line contains integers --- the list of data transfer times through each computer's wire ().
출력
Print a single integer --- the minimum possible total network latency.
힌트
In the first example test, Cupa should connect computers and to the hub, and connect computer to computer . In this case, , , and . The answer is .
In the second example test, the computers should be connected in a chain leading to the hub in arbitrary order. The total network latency is .