#include using namespace std; long long br_stapova,dubina,br_rupa=1,br_rupa1=1; time_t start,stop; double time_limit(){ return (stop-start); } struct stapici{ long long penal, visina; int indx; } sticks[1000005]; struct rupe{ int dubina; vector indx_stick; } rupcage[1000005], rupcage1[1000005]; bool cmp1(stapici a,stapici b){ return a.penal>b.penal; } bool cmp2(stapici a,stapici b){ return a.visina>b.visina; } long long stepen3(long long a){ return a*a*a; } void input(){ freopen("sticks.in","r",stdin); freopen("sticks.out","w",stdout); scanf("%d %d",&br_stapova,&dubina); for (int i=1;i<=br_stapova;i++){ scanf("%lld",&sticks[i].visina); sticks[i].indx=i; } for (int i=1;i<=br_stapova;i++){ scanf("%lld",&sticks[i].penal); } } void ispis(int num){ if(num==1){ printf("%lld\n",br_rupa); for (int i=1;i<=br_rupa;i++){ long long n=rupcage1[i].indx_stick.size(); printf("%lld ",n); for (int j=0;j=0){ rupcage[br_rupa].indx_stick.push_back(sticks[i].indx); rupcage[br_rupa].dubina-=sticks[i].visina; idx[i]=1; } else{ bool naso=0; for (int j=1;j<=br_rupa;j++){ if(rupcage[j].dubina-sticks[i].visina>=0){ rupcage[j].indx_stick.push_back(sticks[i].indx); rupcage[j].dubina-=sticks[i].visina; naso=1; idx[i]=1; break; } } if(!naso){ if(stepen3(br_rupa)<=sticks[i].penal){ br_rupa++; rupcage[br_rupa].dubina=dubina; rupcage[br_rupa].indx_stick.push_back(sticks[i].indx); rupcage[br_rupa].dubina-=sticks[i].visina; idx[i]=1; } } } } // printf("POSLE PRVE RUPE: %lld\n",br_rupa); // for (int i=1;i<=br_rupa;i++){ // printf("%d ",rupcage[i].dubina); // for (int j=0;j=0){ rupcage[j].indx_stick.push_back(sticks[i].indx); // printf("%d\n\n\n",br_rupa); // for (int i=1;i<=br_rupa;i++){ // printf("\n\n\n%d\n",rupcage[i].dubina); // for (int j=0;j0){ // printf("%d %d %d\n",sticks[i].indx,j,rupcage[j].dubina); rupcage[j].indx_stick.push_back(sticks[i].indx); rupcage[j].dubina-=sticks[i].visina; score+=sticks[i].penal; pk2=1; // printf("%d %d\n",j,rupcage[j].dubina); break; } } if(!pk2){ // printf("%d\n",sticks[i].indx); // for (int j=1;j<=br_rupa;j++){ // printf("%d ",rupcage[j].dubina); // } // printf("\n"); br_rupa++; rupcage[br_rupa].dubina=dubina; rupcage[br_rupa].indx_stick.push_back(sticks[i].indx); rupcage[br_rupa].dubina-=sticks[i].visina; } } } else{ // printf("USAO VAMO\n"); bool pk2=0; for (int j=1;j<=br_rupa;j++){ if (rupcage[j].dubina>0){ // printf("P:%d\n",rupcage[j].dubina); rupcage[j].indx_stick.push_back(sticks[i].indx); rupcage[j].dubina-=sticks[i].visina; score+=sticks[i].penal; pk2=1; break; } } if(!pk2){ br_rupa++; printf("%d\n",br_rupa); rupcage[br_rupa].dubina=dubina; rupcage[br_rupa].indx_stick.push_back(sticks[i].indx); rupcage[br_rupa].dubina-=sticks[i].visina; } } } } // ispis(); return score; } else if (a=='H'){ bool idx[1000005]; sort(sticks+1,sticks+1+br_stapova,cmp2); rupcage[br_rupa1].dubina=dubina; for (int i=1;i<=br_stapova;i++){ // printf("%lld ",sticks[i].penal); idx[i]=0; if(rupcage[br_rupa1].dubina-sticks[i].visina>=0){ rupcage[br_rupa1].indx_stick.push_back(sticks[i].indx); rupcage[br_rupa1].dubina-=sticks[i].visina; idx[i]=1; } else{ bool naso=0; for (int j=1;j<=br_rupa1;j++){ if(rupcage[j].dubina-sticks[i].visina>=0){ rupcage[j].indx_stick.push_back(sticks[i].indx); rupcage[j].dubina-=sticks[i].visina; naso=1; idx[i]=1; break; } } if(!naso){ if(stepen3(br_rupa1)<=sticks[i].penal){ br_rupa1++; rupcage[br_rupa1].dubina=dubina; rupcage[br_rupa1].indx_stick.push_back(sticks[i].indx); rupcage[br_rupa1].dubina-=sticks[i].visina; idx[i]=1; } } } } // printf("POSLE PRVE RUPE: %lld\n",br_rupa); // for (int i=1;i<=br_rupa;i++){ // printf("%d ",rupcage[i].dubina); // for (int j=0;j=0){ rupcage[j].indx_stick.push_back(sticks[i].indx); // printf("%d\n\n\n",br_rupa); // for (int i=1;i<=br_rupa;i++){ // printf("\n\n\n%d\n",rupcage[i].dubina); // for (int j=0;j0){ // printf("%d %d %d\n",sticks[i].indx,j,rupcage[j].dubina); rupcage[j].indx_stick.push_back(sticks[i].indx); rupcage[j].dubina-=sticks[i].visina; score+=sticks[i].penal; pk2=1; // printf("%d %d\n",j,rupcage[j].dubina); break; } } if(!pk2){ // printf("%d\n",sticks[i].indx); // for (int j=1;j<=br_rupa;j++){ // printf("%d ",rupcage[j].dubina); // } // printf("\n"); br_rupa1++; rupcage[br_rupa1].dubina=dubina; rupcage[br_rupa1].indx_stick.push_back(sticks[i].indx); rupcage[br_rupa1].dubina-=sticks[i].visina; } } } else{ // printf("USAO VAMO\n"); bool pk2=0; for (int j=1;j<=br_rupa1;j++){ if (rupcage[j].dubina>0){ // printf("P:%d\n",rupcage[j].dubina); rupcage[j].indx_stick.push_back(sticks[i].indx); rupcage[j].dubina-=sticks[i].visina; score+=sticks[i].penal; pk2=1; break; } } if(!pk2){ br_rupa1++; // printf("%d\n",br_rupa); rupcage[br_rupa1].dubina=dubina; rupcage[br_rupa1].indx_stick.push_back(sticks[i].indx); rupcage[br_rupa1].dubina-=sticks[i].visina; } } } } // ispis(); return score; } } void reset(){ for (int i=1;i<=br_rupa;i++){ rupcage1[i].indx_stick=rupcage[i].indx_stick; rupcage[i].dubina=dubina; rupcage[i].indx_stick.clear(); } } int main(){ time(&start); input(); ///ispis doraditi pre slanja long long score1=sortiraj_u_rupe('P'); for (int i=1;i<=br_rupa;i++){ long long n=rupcage[i].indx_stick.size(); if (n==0) br_rupa--; } reset(); score1+=stepen3(br_rupa); long long score2=sortiraj_u_rupe('H'); for (int i=1;i<=br_rupa;i++){ long long n=rupcage[i].indx_stick.size(); if (n==0) br_rupa--; } if (score1>score2) ispis(2); else ispis(1); return 0; } ///101 i 193 vreme