binary search C++
```\nclass Solution {\npublic:\n    int minMoves(const vector& nums, int k) {\n        vector one;\n        int n = nums.size();\n        for (int i = 0; i < n;
```\nclass Solution {\npublic:\n    int minMoves(const vector<int>& nums, int k) {\n        vector<int> one;\n        int n = nums.size();\n        for (int i = 0; i < n; ++i) {\n            if (nums[i]) {\n                one.push_back(i - one.size());\n            }\n        }\n        n = one.size();\n\n        function<bool(int)> can = [&](int value) {\n            int p = (k - 1) / 2;\n            int need = 0;\n            for (int i = 0; i < k; ++i) {\n                need += abs(one[i] - one[p]);\n            }\n            if (need <= value) return true;\n            for (int i = 0; i + k < n; ++i) {\n                need += one[i];\n                need += one[i + k];\n                ++p;\n                need -= one[p];\n                need -= one[p - (k & 1)];\n                if (need <= value) return true;\n            }\n            return false;\n        };\n\n        int first = 0, len = numeric_limits<int>::max();\n        while (len > 0) {\n            int step = len >> 1;\n            int mid = first + step;\n            if (!can(mid)) {\n                first += step + 1;\n                len -= step + 1;\n            } else {\n                len = step;\n            }\n        }\n        return first;\n    }\n};
[]