Intuition/ Hint
Intuition\n\n For large k, it can be said that exhausting maxChanges is always better. In cases where k is small, it is possible that exhausting maxChanges is n
# Intuition\n\n* For large k, it can be said that exhausting maxChanges is always better. In cases where k is small, it is possible that exhausting maxChanges is not the most optimal way.\n*  If we want to pick x number of ones, it can be proved that putting dylan at the x/2th one will yield minimum cost.\n\n\n# Code\n```\nclass Solution {\npublic:\n    long long minimumMoves(vector<int>& nums, int k, int maxChanges) {\n        long long n = nums.size();\n        \n        vector<long long> oneind;\n        for(int i=0;i<n;i++){\n            if(nums[i]==1)oneind.push_back(i);\n        }\n    \n        int o = oneind.size();\n        vector<long long> pre(o+1);\n        \n        pre[0]= 0;\n        \n        for(long long i=0;i<o;i++){\n            pre[i+1] = pre[i]+oneind[i];\n        }\n        \n        long long ans = 0x3f3f3f3f3f3f3f3fLL;\n        \n        for(long long i= max(0,k-maxChanges);i<=k;i++){\n            long long tmp = (k-i)*2;\n    \n            long long mn = 0x3f3f3f3f3f3f3f3fLL;\n            for(long long j=0; o>0 && i>0 && i<=o && j<o-i+1;j++){\n                long long md = (j+j+i-1)/2;\n                long long lr= oneind[md]*(md-j+1) -(pre[md+1]-pre[j]);\n                long long rl = pre[j+i]-pre[md+1] - oneind[md]*(j+i-1-md);\n               mn = min(mn,  lr+rl );\n            }\n            \n            if(i>0)\n            tmp+=mn;\n            \n            if(tmp<ans) ans = tmp;\n            else break;\n        }\n        \n        return ans;\n    }   \n};\n```
['C++']