Hi guys,
I was just trying random problems from the topcoder archive when i came across the following problem
http://www.topcoder.com/stat?c=problem_statement&pm=1918&rd=5006
It seemed a little weird to me , the problem statement itself. According to the tutorials and stats its an easy problem .
I am not able to get it .
I have my solution below ( incorrect of course ) ... It passes all the basics tests in the arena . but fails at system test very badly . Could someone please explain the problems statement or point to the flaw int my code
( warning : it is very messy code .... please dont judge me by it :)) ... )
public int[] getOrdering(int[] height, int[] bloom, int[] wilt)
{
for(int i=0;i<height.length-1;i++)
{
int val=height[i];
int index=i;
for(int j=i;j<height.length;j++)
{
if(val<height[j])
{
val=height[j];
index=j;
}
}
int temp;
temp=height[index];
height[index]=height[i];
height[i]=temp;
temp=bloom[index];
bloom[index]=bloom[i];
bloom[i]=temp;
temp=wilt[index];
wilt[index]=wilt[i];
wilt[i]=temp;
}
int out[]=new int[height.length];
for(int i=0;i<height.length;i++)
out[i]=height[i];
for(int i=1;i<height.length;i++)
{
int numi=out[i];
int indi=i;
for(int k=0;k<height.length;k++)
if(height[k]==numi)
{
indi=k;
break;
}
for(int j=0;j<i;j++)
{
int num=out[j];
int indj=j;
for(int k=0;k<height.length;k++)
if(height[k]==num)
{
indj=k;
break;
}
if(bloom[indi]<=wilt[indj]&&bloom[indj]<=wilt[indi])
{
for(int p=i-1;p>=j;p--)
out[p+1]=out[p];
out[j]=numi;
break;
}
}
}
return out;
}
if(bloom[indi]<=wilt[indj]&&bloom[indj]<=wilt[indi]) instead of
if(bloom[indi]<=wilt[indj]||bloom[indj]<=wilt[indi])....
I know its all wrong .... but its all i came up with . :(