You are given two arrays arr and brr of the same length, and a number k.
You are allowed two types of operations on arr:
Rearrangement Operation —
You can divide arr into multiple continuous pieces and reorder those pieces in any way.
This entire rearrangement action costs k (no matter how many pieces you break into).
Value Adjustment Operation —
You may increase or decrease any element in arr.
If you change a value by x, the cost is x.
Your goal is to make arr exactly equal to brr while minimizing the total cost.
Return the minimum cost.
Input: arr = [1,2,3], brr = [1,2,3], k = 10
Output: 0
Explanation:
Arrays are already identical, so cost is 0.
Input: arr = [4, 10, -1], brr = [-1, 4, 10], k = 3
Output: 3
Explanation:
Rearrange arr → [-1, 4, 10], cost = 3. Now arr matches brr exactly, so no extra value adjustments needed. Total cost = 3.
Accepted:
Submission: