#include #include #include #include #include using namespace std; #define FOR(x,y) for(int x = 0;x < y;x++) #define LLI long long int template class UF { public: vector par,rank,cnt; UF() {par=rank=vector(um,0); cnt=vector(um,1); for(int i=0;irank[y]) return par[x]=y; rank[x]+=rank[x]==rank[y]; return par[y]=x; } }; int main() { int n; cin >> n; vector data(n); int sum = 0; FOR(i, n) { cin >> data[i]; sum += data[i]; } int maxSize = sqrt(sum) + 1; cout << "maxSize:" << maxSize << endl; int minOperation = 1000000000; for(int i = 1; i < maxSize*2;i += 2) { if((i/2) * (i/2) > sum) { continue; } cout << "i:" << i << endl; int middleIndex = i / 2; int count = 0; for(int x = 0;x < i;x++) { int height = middleIndex - abs(middleIndex-x) + 1; cout << "height:" << height << endl; if(x < n) { count += abs(height - data[x]); } else { count += height; } } for(int x = i;x < n;x++) { count += data[x]; } minOperation = min(minOperation, count); } cout << minOperation << endl; return 0; }