Simple Java Solution | Beats 100% ✅✅✅
class Solution {\n    public long minimumMoves(int[] nums, int k, int maxChanges) {\n        int n = nums.length;\n      int[] cum = new int[n+1];\n      for(in
class Solution {\n    public long minimumMoves(int[] nums, int k, int maxChanges) {\n        int n = nums.length;\n      int[] cum = new int[n+1];\n      for(int i = 0;i < n;i++){\n        cum[i+1] = cum[i] + nums[i];\n      }\n\n      long[] wcum = new long[n+1];\n      for(int i = 0;i < n;i++){\n        wcum[i+1] = wcum[i] + (long)nums[i] * i;\n      }\n\n      long ans = Long.MAX_VALUE;\n      for(int i = 0;i < n;i++){\n        int low = -1, high = n + 1;\n        while(high - low > 1){\n          int h = high+low>>1;\n          int pick = cum[Math.min(n, i+h+1)] - cum[Math.max(0, i-h)] + (h >= 2 ? maxChanges : 0);\n          if(pick >= k){\n            high = h;\n          }else{\n            low = h;\n          }\n        }\n        int rem = k;\n        long cost = 0;\n        if(rem > 0 && nums[i] == 1){\n          rem--;\n        }\n        if(rem > 0 && high >= 1 && i-1 >= 0 && nums[i-1] == 1){\n          rem--;\n          cost++;\n        }\n        if(rem > 0 && high >= 1 && i+1 < n && nums[i+1] == 1){\n          rem--;\n          cost++;\n        }\n        if(high >= 2){\n          int use = Math.min(rem, maxChanges);\n          rem -= use;\n          cost += 2L*use;\n\n          int u = 0;\n          {\n            int hh = Math.min(n, i + high + 1);\n            int ll = Math.min(n, i + 2);\n            cost += wcum[hh] - wcum[ll] - (long) i * (cum[hh] - cum[ll]);\n            u += cum[hh] - cum[ll];\n          }\n          {\n            int hh = Math.max(0, i-1);\n            int ll = Math.max(0, i-high);\n            cost += -(wcum[hh] - wcum[ll]) + (long) i * (cum[hh] - cum[ll]);\n            u += cum[hh] - cum[ll];\n          }\n\n          assert u >= rem;\n          cost -= (long)high * (u-rem);\n        }\n        ans = Math.min(ans, cost);\n      }\n      return ans;\n    }\n}\n```
['Java']