For the problem CSEQ, I mathematically could prove that the total ways to create a non-decreasing sequence of length K (1<= K <= N) equals choose(K + R - L, K) (the same formula given in the ediorial).
Then we can see that choose(K + R - L, K)*(K + R - L + 1)/(K + 1) equals choose(K + R - L + 1, K + 1). Hence in my code here, I wrote a for loop which starts with sumtemp intialised to 1 and which multiplies sumtemp with (j + R - L)/j thus creating the jth element of the sequence. Now this term is added to ans every time in the loop and I also have added the modulus statement there to avoid overflow.
This gives me a correct ans to some cases which I found out manually and then verified with the code, but codechef isn’t accepting my solution. Can anyone help me find the mistake in my approach?