current and wanted. Your job is to turn current into exactly wanted. Two actions are available, as many times as you like and in any order:
- **Reshuffle.** Cut current into any number of contiguous pieces and put the pieces back together in any order. Each such operation costs shuffle_fee.
- **Adjust.** Add a positive integer x to any element or subtract it. This costs x.
Return the minimum total cost.current=[5, -1, 8], wanted=[-2, 9, 4], shuffle_fee=3 → 6
Without reordering it costs 7 + 10 + 4 = 21. Reorder the pieces into [-1, 8, 5] for a fee of 3, then adjust by 1 + 1 + 1 = 3. Total 6.
current=[1, 2], wanted=[2, 1], shuffle_fee=10 → 2
Reordering costs 10, while simply nudging both numbers costs 1 + 1 = 2.
current=[4, 4, 4], wanted=[4, 4, 4], shuffle_fee=0 → 0
current=[5, -1, 8], wanted=[-2, 9, 4], shuffle_fee=3
6
Run checks the first 3 tests in your browser. Submit checks all 128 tests on the server, hidden ones included.