A race timing system records n checkpoint values in course order. Count the number of ways to choose exactly k positions p_1 < p_2 < ... < p_k such that the chosen values are strictly increasing (value[p_1] < value[p_2] < ... < value[p_k]). That is, count the strictly increasing subsequences of length exactly k. Two choices differ if they use different sets of positions, even when the values match.
Line 1: two integers n and k.
Line 2: n space-separated integers, the checkpoint values in course order.
A single integer: the number of strictly increasing length-k subsequences.
Example 1
Input
4 2 1 2 3 4
Expected
6
Explanation
Any of the 6 position pairs (i<j) has strictly increasing values, so there are 6 length-2 subsequences.
Example 2
Input
5 3 1 3 2 3 4
Expected
5
Explanation
The strictly increasing length-3 choices count to 5: 1,3,4 (two ways, via each of the two 3's), 1,2,3, 1,2,4, and 2,3,4.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →