Dictionary
InterviewTime limit2sMemory limit128 MB
Construct the K-th lexicographically smallest string made of N 'a's and M 'z's using combinatorial counting, or report -1 if K exceeds the total count.
- Level
Medium5 of 10
- Topics
- Combinatorics, Greedy, Math
- Solved
- No attempts yet
Problem
A dictionary contains every string made of exactly N letters a and M letters z, sorted in lexicographic order. Equal letters are indistinguishable, and no other letters appear.
Given N, M, and K, find the K-th string in this dictionary.
Input
The first line contains three integers N, M, and K in that order.
Output
Print the K-th string in the dictionary on the first line. If the dictionary contains fewer than K strings, print -1.
Constraints
- 1 <= N, M <= 100
- 1 <= K <= 1,000,000,000