#include #include #include #define MAX_N 100 using namespace std; int piramidd(int x,int n){ //n段のピラミッド列を構成するとして、x番目の段数を返す if(x > n){ return n - (x-n); }else{ return x; } } int main(){ int n; int total = 0; int min = 99999999; int tmp = 0,tmp2 = 0,tmp3=0; vector A(200,0); cin >> n; for(int d =0;d > A[d]; total += A[d]; } int max_h = sqrt(total); // cout <<"max:" << max_h << " " <<"total:"<< total << endl; if(max_h > n){ // cout <<"change:"<< n << endl; max_h = n; } //if(max_h > 50) max_h = 50; // cout << "max_h:" << max_h << endl; //sqrt(total) ~ 1段まで ピラミッドを構成してみる。 for(int d = max_h; d > 0; d--){ if(total == d*d){ for(int e = 0; e <= 2*d-2;e++){ if( A[e]-piramidd(e+1,d)>0) tmp+= A[e]-piramidd(e+1,d); else tmp2 += (piramidd(e+1,d)- A[e]); // cout << "A[e]:"<< A[e] << " | " << "pi(e,d)" << piramidd(e+1,d) << " " << A[e]-piramidd(e+1,d) << endl; } // cout << "tmp2:" << tmp2 << " tmp:" << tmp<< endl; }else{ //ゴミ捨て場に移す必要がある for(int e = 0; e <= 2*d-2;e++){ if( A[e]-piramidd(e+1,d)>0) tmp+= A[e]-piramidd(e+1,d);//多くつまれている場合 else tmp2 += (piramidd(e+1,d)- A[e]);//不足分 // cout << "A[e]:"<< A[e] << " | " << "pi(e,d)" << piramidd(e+1,d) << " " << A[e]-piramidd(e+1,d) << " total:"<< tmp << endl; } for(int e = 2*d-1; e < n;e++){ tmp3 += A[e]; } tmp += tmp3;//捨てる分は 合計-必要な数-不足分? // cout << "tmp2:" << tmp2 << " tmp:" << tmp << " tmp3:" << tmp3< tmp){ tmp = tmp2;} if(min > tmp){ min = tmp; } tmp = 0; tmp2 = 0; tmp3 = 0; // cout << "test^^"<< endl; } cout << min << endl; return 0; }