LCC '25 Contest 3 S1 - Holiday Assembly Line

View as PDF

Submit solution

Points: 7 (partial)
Time limit: 1.0s
Memory limit: 256M

Author:
Problem type

Christmas is coming up, and Santa needs to finish wrapping all his presents! He must purchase equipment to establish some assembly lines and hire K elves to operate them. When hiring elves, Santa can either place them at an already existing assembly line, or he can open up a new assembly line and place the elf there. The cost of hiring the i^{th} elf to work at the j^{th} assembly line is A\cdot i+B\cdot j. Although Santa only has space for up to N assembly lines, he can have an unlimited number of elves working at any assembly line. What is the minimum total cost required to hire all K elves?

Input Specification

One line, containing four integers N,K,A,B

Output Specification

Output the minimum total cost. Note that this number may be too large for a 32-bit integer.

Constraints

Subtask 1 [15%]

1\leq N\leq K\leq 10^3

1\leq A,B\leq 10^5

Subtask 2 [85%]

1\leq N\leq K\leq 10^6

1\leq A,B\leq 10^9

Sample Input 1

10 6 3 4

Output for Sample Input 1

70

Explanation of Output for Sample Input 1

Consider the following table, where the number in each cell represents the cost for hiring the i^{th} elf to work at the j^{th} assembly line. As a reminder, cost = 3\cdot i + 4\cdot j.

j=1 j=2 j=3 j=4 j=5
i=1 7 11 15 19 23
i=2 10 14 18 22 26
i=3 13 17 21 25 29
i=4 16 20 24 28 32
i=5 19 23 27 31 35
i=6 22 26 30 34 38

The minimum cost to hire 6 elves is shown by the boxed numbers. 7+10+11+13+14+15=70.

Sample Input 2

3 5 4 2

Output for Sample Input 2

46

Comments

There are no comments at the moment.