Tap here to switch tabs
Problem
Submissions

Problem: Minimum Cost to Make Arrays Identical

Try to solve the Minimum Cost to Make Arrays Identical problem.

Statement

You are given two integer arrays arr and brr of equal length, and an integer k.

You can perform the following operations on arr:

  • Split arr into contiguous subarrays and rearrange them in any order. This operation costs k in total and can be performed at most once.

  • Increment or decrement any element of arr by 11. The cost of each such modification is 11.

Return the minimum total cost required to make arr equal to brr.

Constraints:

  • 1≤1 \leq arr.length == brr.length ≤105\leq 10^5

  • 0≤0 \leq k ≤2imes1010\leq 2 imes 10^{10}

  • −105≤-10^5 \leq arr[i] ≤105\leq 10^5

  • −105≤-10^5 \leq brr[i] ≤105\leq 10^5

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Minimum Cost to Make Arrays Identical

Try to solve the Minimum Cost to Make Arrays Identical problem.

Statement

You are given two integer arrays arr and brr of equal length, and an integer k.

You can perform the following operations on arr:

  • Split arr into contiguous subarrays and rearrange them in any order. This operation costs k in total and can be performed at most once.

  • Increment or decrement any element of arr by 11. The cost of each such modification is 11.

Return the minimum total cost required to make arr equal to brr.

Constraints:

  • 1≤1 \leq arr.length == brr.length ≤105\leq 10^5

  • 0≤0 \leq k ≤2imes1010\leq 2 imes 10^{10}

  • −105≤-10^5 \leq arr[i] ≤105\leq 10^5

  • −105≤-10^5 \leq brr[i] ≤105\leq 10^5