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

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

Candy Factory

시간 제한1초메모리 제한2048 MB

요약
n개 종류의 사탕 개수가 주어질 때, 정확히 k가지 종류로 이루어진 묶음으로 남김없이 나누도록 더해야 하는 최소 사탕 개수를 구한다.
난이도

보통10점 중 6점

유형
수학, 그리디, 정렬, 조합론
정답자
아직 제출이 없습니다

문제

The International Consortium of Popular Candies (ICPC) is hosting a prestigious candy festival for candy lovers worldwide. The consortium has asked nn candy factories to produce candies for the event. Each of the nn factories has produced some quantity of a unique type of candy.

Packs of candies will be given to the participants at the festival. A candy pack must consist of exactly kk candies of different types. Two candy packs may contain different sets of kk candies.

There may be unavoidably some leftover candies given the quantities of candies that the nn factories have already produced. The ICPC does not want to waste any of the candies produced, and is willing to create extra packs of candy to ensure this. The ICPC can order any of the nn factories to produce additional candies. What is the minimum quantity of additional candies that must be ordered, so that there will be no leftover candies after packing?

입력

The first line of input has two integers nn and kk (1≤k≤n≤5,0001 \leq k \leq n \leq 5\\,000).

The next nn lines each have a single integer between 11 and 10910^9. The integer on the ithi^{\text{th}} line is the quantity of candies that the ithi^{\text{th}} factory has produced.

출력

Output a single integer, the minimum quantity of additional candies that must be ordered.

예제1

  1. 예제 1

    입력
    4 3
    1
    3
    4
    1
    
    예상 출력
    3