Number Concatenation
Time limit2sMemory limit128 MB
Given a subsequence left after deleting digits from the concatenation of 1,2,...,N, find the smallest N that could produce it.
- Level
Hard8 of 10
- Topics
- String matching, Binary search, Greedy, Dynamic programming
- Solved
- No attempts yet
Problem
If every integer from 1 through N is written in order without spaces, it forms a string such as 123456789101112...N.
Some digits were deleted from this string. It is also possible that no digit was deleted. The remaining digits keep their original order and are concatenated into one digit string.
Given the remaining digit string, find the smallest possible N that could have produced it.
Input
The first line contains the digit string left after deletions. Its length is at most 3,000.
Output
Print the smallest possible N that can produce the given string.