The examples you provided are incorrect. The smallest sum you can generate from three
distinct integers between 1 and N is 1+2+3=6, so there can be no sequence with a sum of 5! Also the llimitation K<=N doesn't make a lot of sense! K must be in the range 6 .. 3*N-3, because N+(N-1)+(N-2) = 3*N-3 is the greatest sum you can calculate from these numbers.
Your code has nothing at all to do with the problem! You should show more effort - all you do is ask for others to do your homework.
I suggest that you write a program to generate all valid combinations of balls that could be drawn, count the combinations, calculate the sum, and count the cases where the sum is no greater than K. It won't be fast, but should get you the correct results.
Here's some pseudo code, omitting input and initialization:
for (every valid sequence {first_number, second_number, third_number})
increment sequence_counter
sum = first_number + second_number + third_number
if (sum <= K)
increment sum_not_greater_counter
print sum_not_greater_counter / sequence_counter
That's already more help than you deserve for showing no effort. But it's so basic that you may find you can apply the same idea (generating all combinations) on other problems as well.