c++ siding window
\ntypedef long long ll;\nclass Solution {\npublic:\n    int minMoves(vector<int>& n, int k) {\n        if (k == 1) return 0;\n        vector<int> v;\n        fo
```\ntypedef long long ll;\nclass Solution {\npublic:\n    int minMoves(vector<int>& n, int k) {\n        if (k == 1) return 0;\n        vector<int> v;\n        for(int i=0; i<n.size(); i++) {\n            if (n[i] == 1) v.push_back(i);\n        }\n        ll ret = 1e18;\n        ll presum = 0, postsum = 0;\n        for(int i=0; i<k / 2; i++) {\n            presum += v[i];\n        }\n        for(int i=k/2; i<k; i++) {\n            postsum += v[i];\n        }\n        if (k % 2) postsum -= v[k/2];\n        ret = min(ret, (postsum - presum));\n        for(int i=k; i<v.size(); i++) {\n            int mid = (i - k + 1 + i) / 2;\n            postsum += v[i];\n            presum -= v[i - k];\n            if (k % 2) {\n                presum += v[mid - 1];\n                postsum -= v[mid];\n            } else {\n                presum += v[mid];\n                postsum -= v[mid];\n            }\n            ret = min(ret, postsum - presum);\n        }\n        while (k > 1) {\n            ret -= (k - 1);\n            k -= 2;\n        }\n        return ret;\n    }\n};\n```
[]