values and an integer fee. Cut the array into one or more non-empty contiguous pieces (every element goes into exactly one piece, and the order stays the same).
Each piece costs fee plus a repeat penalty: the number of its elements whose value appears at least twice within that piece. Elements whose value is unique in the piece add nothing. For example, the piece [5, 1, 5, 5, 2] has a penalty of 3 (the three 5s), so it costs fee + 3.
Return the minimum total cost of a split.values=[4, 0, 4, 1, 1, 0], fee=3 → 8
The best cut is [4, 0, 4, 1] and [1, 0]: the first piece costs 3 + 2 (two 4s), the second costs 3, for a total of 8. Keeping everything in one piece would cost 3 + 6 = 9.
values=[2, 2, 2, 2], fee=1 → 4
Four single-element groups have no repeats, so the total is 4 · 1 = 4.
values=[0, 1, 2], fee=7 → 7
values=[4, 0, 4, 1, 1, 0], fee=3
8
Run checks the first 3 tests in your browser. Submit checks all 109 tests on the server, hidden ones included.