Tap here to switch tabs
Problem
Submissions

Problem: Minimum Sum of Squared Difference

Try to solve the Minimum Sum of Squared Difference problem.

Statement

You are given two integer arrays nums1 and nums2, both of length n, and two integers k1 and k2.

You may choose any element in nums1 and increment or decrement it by 11 at most k1 times in total. Similarly, you may choose any element in nums2 and increment or decrement it by 11 at most k2 times in total.

Return the minimum possible sum of squared differences between corresponding elements of nums1 and nums2, which is defined as ∑i=0n−1(‘nums1[i]‘−‘nums2[i]‘)2\sum_{i=0}^{n-1} (`nums1[i]` - `nums2[i]`)^2, after applying at most k1 modifications to nums1 and at most k2 modifications to nums2.

Constraints:

  • n ==== nums1.length ==== nums2.length

  • 1≤1 \leq n ≤105\leq 10^5

  • 0≤0 \leq nums1[i], nums2[i] ≤105\leq 10^5

  • 0≤0 \leq k1, k2 ≤109\leq 10^9

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Minimum Sum of Squared Difference

Try to solve the Minimum Sum of Squared Difference problem.

Statement

You are given two integer arrays nums1 and nums2, both of length n, and two integers k1 and k2.

You may choose any element in nums1 and increment or decrement it by 11 at most k1 times in total. Similarly, you may choose any element in nums2 and increment or decrement it by 11 at most k2 times in total.

Return the minimum possible sum of squared differences between corresponding elements of nums1 and nums2, which is defined as ∑i=0n−1(‘nums1[i]‘−‘nums2[i]‘)2\sum_{i=0}^{n-1} (`nums1[i]` - `nums2[i]`)^2, after applying at most k1 modifications to nums1 and at most k2 modifications to nums2.

Constraints:

  • n ==== nums1.length ==== nums2.length

  • 1≤1 \leq n ≤105\leq 10^5

  • 0≤0 \leq nums1[i], nums2[i] ≤105\leq 10^5

  • 0≤0 \leq k1, k2 ≤109\leq 10^9