runtime error in c code

#include<stdio.h>
#include<stdlib.h>
int main()
{
int t ,a,b,q,i,j,na,nq,p,k=0,temp,l;
scanf("%d",&t);
if(t>5)
exit(0);
else
{
for(l=0;l<t;l++)
{
scanf("%d %d",&na,&nq);
a=(int
)malloc(na
(sizeof(int)));
b=(int
)malloc(na*(sizeof(int)));
for(i=0;i<na;i++)
scanf("%d",&a[i]);
for(i=0;i<na;i++)
scanf("%d",&b[i]);
p=(int*)malloc(nana(sizeof(int)));
for(i=0;i<na;i++)
for(j=0;j<na;j++)
p[k++]=a[i]+b[j];
for(i=0;i<nana;i++)
{
for(j=0;j<na
na;j++)
{
if(p[i]<p[j])
{
temp=p[i];
p[i]=p[j];
p[j]=temp;
}
}
}
for(i=0;i<nq;i++)
{
scanf("%d",&q);
printf("%d\n",p[q-1]);
}
}
return 0;
}
}

you are using malloc so when the code needs to allocate an array of size more than 2*10^6 it will run out of memory and creates run time memory.

this is one of the possibility , post the link to the question.

I also have the same doubt.I was working on lowest sum question.In that i could allocate memory for 20,000 long long elements but it could not allocate memory for 20,000 * 20,000 long long elements and thats why i think it gave an runtime error(SIGSGEV.
But whats the solution?
I tried static allocation but it doesn’t work for these array sizes.
So the solution till remains veiled.