ABC
InterviewTime limit2sMemory limit512 MB
Find the lexicographically smallest length-N string over A, B, C that has exactly K pairs i < j with S[i] < S[j].
- Level
Medium4 of 10
- Topics
- Greedy, Combinatorics, Implementation
- Solved
- No attempts yet
Problem
Given integers and , write a program that finds a string meeting both of these conditions.
- has length and uses only the characters
A,B, andC. - Exactly pairs satisfy and
S[i] < S[j].
Characters compare in alphabetical order, so A < B < C.
Input
The first line contains and , separated by a space. (, )
Output
Print on the first line the lexicographically smallest string that meets the conditions. If no such exists, print -1.