Key point to note in this question is that the question talks about
DISTINCT prime numbersTo find the max value you need to minimize the other values
We know that the median is 7 Hence
a + b + 7 c + d = 50
Now to find the max value start minimizing the values of a and b, subtract the sum of a + b + 7 from 50 and test answer choices
For instance smallest two prime numbers are 2 , 3 so a = 2 , b = 3
2 + 3 + 7 + c + d = 50
Now c + d = is 50 - 2 - 3 - 7 = 38
Now if you minus the answer choices one by one from 38 you will notice that none of them give you a prime number except 19 but since you need DISTINCT prime numbers 19 is not valid. Since we dint get an answer here try the next set of prime numbers
Next higher set of prime numbers for a and b would be take 2 , 5
2 + 5 + 7 + c + d = 50
So c + d = 36
Now 36 - 29 = 7 but wont work cause we need distinct nos
36 - 23 = 13 prime number works ---> done