AlgoLensArena
ContestlərProblemlərOtaqlar
Vizualizator
← Məsələlər

BAPC22-064.Grinding Gravel

Medium · 4 s · 256 MB

  • icpc
  • bapc
  • 2022

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 888, which can be filled as follows. Put the stones of weight 222 and 666 in the first cell. Now grind the stone of weight 777 into two pieces of weight 333 and 444. Then the other two grid cells get filled by weights 3,53, 53,5 and 4,44, 44,4 respectively.

Giriş formatı

The input consists of:

• One line with two integers nnn and kkk (1≤n≤1001 \leq n \leq 1001≤n≤100, 1≤k≤81 \leq k \leq 81≤k≤8), the number of pieces of gravel and the capacity per grid cell.

• One line with nnn integers w1,…,wnw_1, \dots, w_nw1​,…,wn​ (1≤wi≤1061 \leq w_i \leq 10^61≤wi​≤106 for all iii), the weight of each piece of gravel.

It is guaranteed that w1+w2+⋯+wnw_1 + w_2 + \dots + w_nw1​+w2​+⋯+wn​ is a multiple of kkk.

Çıxış formatı

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.

Qeyd

Source: Benelux Algorithm Programming Contest 2022 · Author: Daan van Gent, Onno Berrevoets · License: CC BY-SA 4.0 · Original: https://bapc.eu · Statement adapted for AlgoLens and shared under the same license.

Nümunələr

Giriş #1

5 8
2 4 5 6 7

Çıxış #1

1

Giriş #2

2 5
12 13

Çıxış #2

4