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

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

Computer Network

면접 대비

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

요약
각 컴퓨터의 선을 허브나 다른 컴퓨터에 연결해 모든 컴퓨터가 허브에 도달하도록 하면서 지연 시간 합을 최소화한다.
난이도

보통10점 중 5점

유형
그리디, 정렬, 트리
정답자
아직 제출이 없습니다

문제

Cupa is building a connected network using nn computers and a single hub.

The computers are numbered from 11 to nn. Each computer ii has an outgoing wire that can transfer one bit of data to the other end in d_id\_i milliseconds.

The hub has kk 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 t_it\_i for each computer ii is defined as the time it takes to send one bit of data from computer ii 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 t_it\_i for each computer ii. He wants the total network latency over all computers, i.e. t_1+t_2+…+t_nt\_1 + t\_2 + \ldots + t\_n, 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 nn and kk --- the number of computers and the number of ports in the hub (1≤k≤n≤1001 \leq k \leq n \leq 100).

The second line contains nn integers d_1,d_2,…,d_nd\_1, d\_2, \ldots, d\_n --- the list of data transfer times through each computer's wire (1≤d_i≤1001 \leq d\_i \leq 100).

출력

Print a single integer --- the minimum possible total network latency.

힌트

In the first example test, Cupa should connect computers 22 and 33 to the hub, and connect computer 11 to computer 33. In this case, t_1=20+10=30t\_1 = 20 + 10 = 30, t_2=30t\_2 = 30, and t_3=10t\_3 = 10. The answer is t_1+t_2+t_3=70t\_1 + t\_2 + t\_3 = 70.

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 10+20+30+40+50=15010 + 20 + 30 + 40 + 50 = 150.

예제4

  1. 예제 1

    입력
    3 2
    20 30 10
    
    예상 출력
    70
    
  2. 예제 2

    입력
    5 1
    10 10 10 10 10
    
    예상 출력
    150
    
  3. 예제 3

    입력
    5 2
    10 10 10 10 10
    
    예상 출력
    90
    
  4. 예제 4

    입력
    6 3
    5 6 2 3 1 4
    
    예상 출력
    27