포럼
문제 ICPC00344

G. Grinding Gravel

설명

During the renovation of your garden, you decide that you want a gravel path running from the street to your front door. Being a member of the Boulders And Pebbles Community, you want this path to look perfect. You already have a regular grid to put the gravel in, as well as a large container of gravel containing exactly as much as the total capacity of the grid.

There is one problem: the gravel does not yet fit perfectly into the grid. Each grid cell has the same (fixed) capacity and every piece of gravel has a certain weight. You have a grindstone that can be used to split the stones into multiple pieces, but doing so takes time, so you want to do a minimal number of splits such that the gravel can be exactly distributed over the grid.

As an example, consider the first sample case. There are three grid cells of size \(8\), which can be filled as follows. Put the stones of weight \(2\) and \(6\) in the first cell. Now grind the stone of weight \(7\) into two pieces of weight \(3\) and \(4\). Then the other two grid cells get filled by weights \(3, 5\) and \(4, 4\) respectively.

제약
입력 형식

The input consists of:
- One line with two integers \(n\) and \(k\) (\(1 \leq n \leq 100\), \(1 \leq k \leq 8\)), the number of pieces of gravel and the capacity per grid cell.
- One line with \(n\) integers \(w_1, \dots, w_n\) (\(1 \leq w_i \leq 10^6\) for all \(i\)), the weight of each piece of gravel.

It is guaranteed that \(w_1 + w_2 + \dots + w_n\) is a multiple of \(k\).

출력 형식

Output the minimal number of times a stone needs to be split into two, such that all the pieces of gravel can be used to fill all the grid cells perfectly.

예제 1
입력
5 8
2 4 5 6 7
출력
1
예제 2
입력
2 5
12 13
출력
4
문제 정보

생성자가 기록되지 않았습니다.

출처 ICPC BAPC 2022

평가 및 의견

G. Grinding Gravel

개요
출제자 난이도 Unrated 레이팅 미적용 의견 0 / 1 공개 집계 (커뮤니티 난이도, 주요 주제, 품질)는 의견이 충분히 모이면 공개됩니다.

Log in to rate problems.

개별 의견

아직 의견이 없습니다. 자격이 된다면 위 양식에서 가장 먼저 평가해 보세요.

풀이 제출

G. Grinding Gravel

게스트로 둘러보고 있습니다. 로그인하면 풀이를 제출하고 진행 상황을 확인할 수 있습니다. 로그인하고 제출하기
공개
C++20 Tab 들여쓰기 · Ctrl+/ 주석 토글 · Enter 자동 들여쓰기
1 1 1 0 공백: 4 · UTF-8