time limit should be is one sec but iam getting time limit exceeded.how to resolve it?

#include<stdio.h>
void quicksort(int a[],int first,int last){
int i, j, pivot, temp;
if(first<last){
pivot=first;
i=first;
j=last;
while(i<j){
while(a[i]<=a[pivot]&&i<last)
i++;
while(a[j]>a[pivot])
j–;
if(i<j){
temp=a[i];
a[i]=a[j];
a[j]=temp;
}
}
temp=a[pivot];
a[pivot]=a[j];
a[j]=temp;
quicksort(a,first,j-1);
quicksort(a,j+1,last);
}
}

int main(){
int n,k,y,t,x,count,i,a[100001],temp[1001];
scanf("%d",&t);
for(x=0;x<t;x++){
scanf("\n%d",&n);
scanf("%d\n",&k);
if(n%2==0){
y=n-k;
}else{
y=n-k-1;
}
count=0;
for(i=0;i<n;i++){
scanf("%d",&a[i]);
}
quicksort(a,0,n);
for(i=0;i<n;i++){
if(a[i]>=a[y]){
count++;}
}
temp[x]=count;
}
for(x=0;x<t;x++){
printf("%d\n",temp[x]);
}
}

//