The K-th Distinct Substring
Among all DISTINCT substrings of S sorted lexicographically, print the K-th, or −1 if fewer than K exist.
Input: the first line has S; the second line has K.
Output: the K-th distinct substring, or −1.
Constraints:
- 1 ≤ |S| ≤ 105
- 1 ≤ K ≤ 1018
Sample Tests
Input 1
aba 3
Output 1
aba
Input 2
ab 5
Output 2
-1
Discussion (opens after you solve — no spoilers before)
No comments yet.