getting wrong answer for CHN03

Hey can you check if my approach for the ques https://www.codechef.com/problems/CHN03 is right or not.
Here is my code:

  #include<iostream>
#include<algorithm>
using namespace std;
int main()
{
		
	int t;
	cin>>t;
	while(t--)
	{
		int n, k, time,te[50][3],pe[50][3],a[50][3],b[151];
		cin>>n>>k>>time;
		long long int sum=0;
		int add[50];
		for(int i=0;i<n;i++)
		{
			cin>>te[i][0]>>te[i][1]>>te[i][2];
		}
		for(int i=0;i<n;i++)
		{
			cin>>pe[i][0]>>pe[i][1]>>pe[i][2];
			for(int j=0;j<3;j++)
			{
				if(te[i][j]>time)
				pe[i][j]=0;
				a[i][j]=pe[i][j];
				
				b[(3*i+j)]=pe[i][j];
			}
		int index=((a[i][0]>a[i][1])?((a[i][0]>a[i][2])?0:2):(a[i][1]>a[i][2])?1:2);
		add[i]=a[i][index];
	
		b[(3*i+index)]=0;
		}
		sort(add,add+n);
		sort(b,b+n*3);

		int i=n-1;
		
		int j=3*n-1;

		while(i>=0&&j>=3*n-k)
		{
			if(add[i]<b[j])
			{
			add[i]=b[j];
			j--;
			}
			i--;
		}
			
		for(int i=0;i<n;i++)
		sum=sum+add[i];
		cout<<sum<<endl;
	}
	return 0;
}

can you tell me few test cases it won’t work for?
.

May be my whole logic is wrong. please tell me