Java Clean Solution
Code\n\nclass Solution {\n\t\tpublic long minimumMoves(int[] nums, int k, int maxChanges) {\n\t\t\tint n = nums.length;\n\t\t\tint[] cum = new int[n+1];\n\t\t\t
# Code\n```\nclass Solution {\n\t\tpublic long minimumMoves(int[] nums, int k, int maxChanges) {\n\t\t\tint n = nums.length;\n\t\t\tint[] cum = new int[n+1];\n\t\t\tfor(int i = 0;i < n;i++){\n\t\t\t\tcum[i+1] = cum[i] + nums[i];\n\t\t\t}\n\n\t\t\tlong[] wcum = new long[n+1];\n\t\t\tfor(int i = 0;i < n;i++){\n\t\t\t\twcum[i+1] = wcum[i] + (long)nums[i] * i;\n\t\t\t}\n\n\t\t\tlong ans = Long.MAX_VALUE;\n\t\t\tfor(int i = 0;i < n;i++){\n\t\t\t\tint low = -1, high = n + 1;\n\t\t\t\twhile(high - low > 1){\n\t\t\t\t\tint h = high+low>>1;\n\t\t\t\t\tint pick = cum[Math.min(n, i+h+1)] - cum[Math.max(0, i-h)] + (h >= 2 ? maxChanges : 0);\n\t\t\t\t\tif(pick >= k){\n\t\t\t\t\t\thigh = h;\n\t\t\t\t\t}else{\n\t\t\t\t\t\tlow = h;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tint rem = k;\n\t\t\t\tlong cost = 0;\n\t\t\t\tif(rem > 0 && nums[i] == 1){\n\t\t\t\t\trem--;\n\t\t\t\t}\n\t\t\t\tif(rem > 0 && high >= 1 && i-1 >= 0 && nums[i-1] == 1){\n\t\t\t\t\trem--;\n\t\t\t\t\tcost++;\n\t\t\t\t}\n\t\t\t\tif(rem > 0 && high >= 1 && i+1 < n && nums[i+1] == 1){\n\t\t\t\t\trem--;\n\t\t\t\t\tcost++;\n\t\t\t\t}\n\t\t\t\tif(high >= 2){\n\t\t\t\t\tint use = Math.min(rem, maxChanges);\n\t\t\t\t\trem -= use;\n\t\t\t\t\tcost += 2L*use;\n\n\t\t\t\t\tint u = 0;\n\t\t\t\t\t{\n\t\t\t\t\t\tint hh = Math.min(n, i + high + 1);\n\t\t\t\t\t\tint ll = Math.min(n, i + 2);\n\t\t\t\t\t\tcost += wcum[hh] - wcum[ll] - (long) i * (cum[hh] - cum[ll]);\n\t\t\t\t\t\tu += cum[hh] - cum[ll];\n\t\t\t\t\t}\n\t\t\t\t\t{\n\t\t\t\t\t\tint hh = Math.max(0, i-1);\n\t\t\t\t\t\tint ll = Math.max(0, i-high);\n\t\t\t\t\t\tcost += -(wcum[hh] - wcum[ll]) + (long) i * (cum[hh] - cum[ll]);\n\t\t\t\t\t\tu += cum[hh] - cum[ll];\n\t\t\t\t\t}\n\n\t\t\t\t\tassert u >= rem;\n\t\t\t\t\tcost -= (long)high * (u-rem);\n\t\t\t\t}\n\t\t\t\tans = Math.min(ans, cost);\n\t\t\t}\n\t\t\treturn ans;\n\t\t}\n\n\t}\n```
['Java']