delivery bread challenge from practice section

I have solved this challenge and it is running perfectly on online compiling website i.e. ideone
But while submitting solution to codechef , it is giving runtime error sigsegv.

problem: http://www.codechef.com/problems/DELIVERY

My solution:

#include
using namespace std;

int main()
{
int t,n,m,cnt,cnt1,flag,time=0;
short int **res;
unsigned long int **st;
unsigned long int b;

cin>>t;
cnt=t;
res=new short int*[t];

while(t)
{
cnt1=0;
time=0;

cin>>n;
cin>>m;
cin>>b;

res[cnt-t]=new short int[m+1];

//allocation
st=new unsigned long int*[m];
for(int i=0;i<m;i++)
{
  st[i]=new unsigned long int[4];
}

for(int i=0;i<m;i++)
{
  cin>>st[i][0];
  cin>>st[i][1];
  cin>>st[i][2];
  st[i][3]=0;
}

unsigned long int min;
int dest=0,minj=-1;


for(int i=0;i<m && time<b;i++)
{
  min=1000000001;
  for(int j=0;j<m;j++)
  {
	 if(st[j][0]==dest && min>st[j][2] && !st[j][3])
	 {
	   min=st[j][2];
	   minj=j;
	 }
  }
  st[minj][3]=1;
  flag=1;
  for(int k=0;k<cnt1;k++)
  {
	if(res[cnt-t][k]==st[minj][1])
	{
	  flag=0;
	}
  }

  if(flag)
  {
	res[cnt-t][cnt1++]=st[minj][1];
  }

  dest=st[minj][1];
  time+=min;
}

res[cnt-t][cnt1]=-1;

//deallocation
for(int i=0;i<m;i++)
{
  delete [] st[i];
}
delete [] st;

t--;

}

int j;
for(int i=0;i<cnt;i++)
{
j=0;
while(res[i][j]!=-1)
{
cout<<res[i][j++]<<" “;
}
cout<<”-1";
cout<<"\n";
}

for(int i=0;i<cnt;i++)
{
delete [] res[i];
}
delete [] res;

return 0;
}

Plzz help me!!!

Can you show the code that you ran on ideone?

http://ideone.com/l4V2Ue this is what happens wen i run the code :frowning:

http://ideone.com/9D0nQo this is my code

maybe u havnt selected the language as c++ 4.8.1

I think the link is private :smiley:

http://ideone.com/9D0nQo … nw public