CF BUDDY
← Problems·

1250B · The Feast and the Bus

1800 · brute force, constructive algorithms, greedy

Problem: Employees of JebTrains are on their way to celebrate the 256-th day of the year! There are nn employees and kk teams in JebTrains. Each employee is a member of some (exactly one) team. All teams are numbered from 11 to kk. You are given an array of numbers t1,t2,,tnt_1, t_2, \dots, t_n where tit_i is the ii-th employee's team number.

JebTrains is going to rent a single bus to get employees to the feast. The bus will take one or more rides. A bus can pick up an entire team or two entire teams. If three or more teams take a ride together they may start a new project which is considered unacceptable. It's prohibited to split a team, so all members of a team should take the same ride.

It is possible to rent a bus of any capacity ss. Such a bus can take up to ss people on a single ride. The total cost of the rent is equal to srs \cdot r burles where rr is the number of rides. Note that it's impossible to rent two or more buses.

Help JebTrains to calculate the minimum cost of the rent, required to get all employees to the feast, fulfilling all the conditions above.

Input Format: The first line contains two integers nn and kk (1n5105,1k80001 \le n \le 5\cdot10^5, 1 \le k \le 8000) — the number of employees and the number of teams in JebTrains. The second line contains a sequence of integers t1,t2,,tnt_1, t_2, \dots, t_n, where tit_i (1tik1 \le t_i \le k) is the ii-th employee's team number. Every team contains at least one employee.

Output Format: Print the minimum cost of the rent.

Sample Cases

Case 1

Input

6 3
3 1 2 3 2 3

Output

6

Case 2

Input

10 1
1 1 1 1 1 1 1 1 1 1

Output

10

Case 3

Input

12 4
1 2 3 1 2 3 4 1 2 1 2 1

Output

12

Similar problems

00:00:00
Loading editor…
Welcome! I'm your coding tutor for this problem. Use the chips below to reveal stored hints or get AI feedback on your code. I'll guide you step by step — never giving away the solution.

Sign in to unlock AI tutor feedback