http://www.spoj.com/problems/BALLSUM/ Consider case : n = 6 k = 8 1 2 3 4 5 6 3 + 6 = 9 5 + 4 = 9 6 + 5 = 11 4 + 6 = 10 Other 11 are < k(=8) AC answer is = 4/5 Why the answer is not 11/15 ?
Your test case is wrong - according to the problem statement, K<=N.
So I tried 6 6 in spojtoolkit, and the expected answer is 2/5. This makes sense, as there are 6 out of 15 possible two ball combinations that sum to 6 or less.
Thanks for pointing this out k<=n.