Is there a way to solve this problem if N <= 10^5

0 <= k <= n

Hey there! Since it is already on Stackoverflow people who want to will solve the problem. I believe this forum is for problems which are USACO based. :slight_smile: