COCI '25 Contest 5 #2 Težina
View as PDF
Strong Karlo is in the gym. An array of
numbers is given, where each number represents the weight of one item in front of Karlo. An integer
is also given, representing the number of different weights Karlo can use.
For each weight type from to
and for each item in the array, Karlo does the following:
1.Divide the item's weight by the weight type and record the integer part of the division (discard the fractional part).
2.Multiply the obtained integer by the item's weight increased by . If the resulting number is greater than
, Karlo replaces it with
.
3.Sum all obtained numbers for that weight type. The obtained sum is called the strength of that weight type.
Karlo is interested in the sum of strengths of all weight types in the gym. Since Karlo does not have time to calculate it, help him solve his problem.
Input Specification
The first line contains the natural numbers and
, the number of items in front of Karlo and the number of weight types Karlo can use.
The second line contains an array of numbers
, the weights of the items in front of Karlo.
Output Specification
Print a single number, the answer to the question from the problem statement.
Constraints
| Subtask | Points | Constraints |
|---|---|---|
| The array a will contain at most |
||
| No additional constraints. |
Sample Input 1
1 2
2
Sample Output 1
12
Sample Input 2
2 1
3 4
Sample Output 2
39
Explanation for Sample Output 2
Karlo will transform the number into
, and the number
into
. Their sum equals
.
Sample Input 3
7 19
1 2 3 4 5 6 7
Sample Output 3
414
Comments