Java O(nlogn)
Apparently the worst solution\n\nclass Solution {\n    public long minimumMoves(int[] nums, int k, int maxChanges) {\n        int n = nums.length;\n        int[
Apparently the worst solution\n```\nclass Solution {\n    public long minimumMoves(int[] nums, int k, int maxChanges) {\n        int n = nums.length;\n        int[] cnt1 = new int[n];\n        for (int i = 0; i < nums.length; i++)\n            cnt1[i] = (i == 0 ? 0 : cnt1[i - 1]) + (nums[i] == 0 ? 0 : 1);\n\n        int[] cnt2 = new int[n];\n        for (int i = n - 1; i >= 0; i--)\n            cnt2[i] = (i == n - 1 ? 0 : cnt2[i + 1]) + (nums[i] == 0 ? 0 : 1);\n\n        long[] presum1 = new long[n];\n\n        for (int i = 0; i < n; i++)\n            presum1[i] = i == 0 ? 0 : presum1[i - 1] + cnt1[i - 1];\n\n        long[] presum2 = new long[n];\n\n        for (int i = n - 1; i >= 0; i--)\n            presum2[i] = i == n - 1 ? 0 : presum2[i + 1] + cnt2[i + 1];\n\n        long ans = Long.MAX_VALUE;\n        for (int i = 0; i < n; i++) {\n            ans = Math.min(ans, cntMove(cnt1, cnt2, presum1, presum2, nums, i, k, maxChanges));\n        }\n        return ans;\n    }\n\n    long cntMove(int[] cnt1, int[] cnt2, long[] presum1, long[] presum2,  int[] nums, int i, int k, int maxChanges)   {\n        long cur = 0;\n        int n = nums.length;\n        int init = 0;\n        if (nums[i] == 1)   {\n            init++;\n            k--;\n        }\n        int consume = 0;\n        if (k > 0 && i > 0 && nums[i - 1] == 1)  {\n            cur++;\n            k--;\n            consume++;\n        }\n        if (k > 0 && i < n - 1 && nums[i + 1] == 1)  {\n            cur++;\n            k--;\n            consume++;\n        }\n\n        if (k == 0)\n            return cur;\n\n        int usedChanges = Math.min(k, maxChanges);\n        k -= usedChanges;\n        cur += usedChanges * 2;\n\n        if (k == 0)\n            return cur;\n\n        int lo = 0;\n        int hi = Math.max(i + 1, n - i);\n\n        while (lo <= hi)    {\n            int mid = lo + (hi - lo) / 2;\n            if (check(cnt1, consume + init, i, mid, k))\n                hi = mid - 1;\n            else\n                lo = mid + 1;\n        }\n\n        int r = lo;\n\n        cur += checkLeft(presum1, cnt1, i - r + 1, i);\n        cur += checkRight(presum2, cnt2, i, i + r - 1);\n\n        return cur - consume;\n    }\n\n    boolean check(int[] cnt, int consume, int i, int r, int k) {\n        return getCnt(cnt, i - r + 1, i + r - 1) - consume >= k;\n    }\n\n\n    int getCnt(int[] cnt, int lo, int hi)   {\n        if (hi >= cnt.length)\n            hi = cnt.length - 1;\n        if (lo < 0)\n            lo = 0;\n        return cnt[hi] - (lo == 0 ? 0 : cnt[lo - 1]);\n    }\n\n    long checkLeft(long[] presum1, int[] cnt1, int lo, int hi)  {\n        int n = presum1.length;\n        if (hi >= n)\n            hi = n - 1;\n        if (lo < 0)\n            lo = 0;\n        return presum1[hi] - (lo == 0 ? 0 : presum1[lo - 1]) - (lo == 0 ? 0 : (long)cnt1[lo - 1] * (hi - lo + 1));\n    }\n\n    long checkRight(long[] presum2, int[] cnt2, int lo, int hi)  {\n        int n = presum2.length;\n        if (hi >= n)\n            hi = n - 1;\n        if (lo < 0)\n            lo = 0;\n        return presum2[lo] - (hi == n - 1 ? 0 : presum2[hi + 1]) - (hi == n - 1 ? 0 : (long)cnt2[hi + 1] * (hi - lo + 1));\n    }\n}\n```
['Binary Tree']