Programming contests

ICPC programozó csapatverseny, házi forduló, 2019. október 30.

October 30, 2019, 10:00 AM – October 30, 2019, 3:00 PM

Cent Savings

To host a regional contest like NWERC, a lot of preparation is necessary: organizing rooms and computers, making a good problem set, inviting contestants, designing T-shirts, booking hotel rooms, and so on. I am responsible for going shopping in the supermarket.


Picture by Tijmen Stam via Wikimedia Commons, cc by-sa

When I get to the cash register, I put all my n items on the conveyor belt and wait until all the other customers in the queue in front of me are served. While waiting, I realize that this supermarket recently started to round the total price of a purchase to the nearest multiple of 10 cents (with 5 cents being rounded upwards). For example, 94 cents are rounded to 90 cents, while 95 are rounded to 100.

It is possible to divide my purchase into groups and to pay for the parts separately. I managed to find d dividers to divide my purchase in up to d + 1 groups. I wonder where to place the dividers to minimize the total cost of my purchase. As I am running out of time, I do not want to rearrange items on the belt.

Input Specification

The input consists of:

  • one line with two integers n (1 ≤ n ≤ 2 000) and d (1 ≤ d ≤ 20), the number of items and the number of available dividers;
  • one line with n integers p1, …, pn (1 ≤ pi ≤ 10 000 for 1 ≤ i ≤ n), the prices of the items in cents. The prices are given in the same order as the items appear on the belt.

Output Specification

Output the minimum amount of money needed to buy all the items, using up to d dividers.

Sample Input 1

  1. 5 1
  2. 13 21 55 60 42
download as text file

Output for Sample Input 1

  1. 190
download as text file

Sample Input 2

  1. 5 2
  2. 1 1 1 1 1
download as text file

Output for Sample Input 2

  1. 0
download as text file

Original Problem

Northwestern Europe Regional Contest, 2014

University of Debrecen; Faculty of Informatics; v. 09/30/2024