Exciting Startup
InterviewTime limit3sMemory limit512 MB
Find the smallest number of pieces b so that a string of length t split into b ordered pieces, each carrying a suffix "_a/b", fits in n-character messages.
- Level
Medium5 of 10
- Topics
- Binary search, Math, Implementation, Brute force
- Solved
- No attempts yet
Problem
In the messaging app Alice built, one message is at most characters long.
Cathy, her first user, wants to send a single string of length . Since is larger than , the string does not fit in one message. She cuts it into pieces in order and sends the -th piece as the -th message. A piece may be empty.
So the messages can be read in order, Cathy appends an indicator of the exact form _a/b after the piece, where is the number of that message and is the total number of messages. Both numbers are written in decimal with no leading zeros. The indicator counts toward the limit of characters, so the length of the -th message is (length of the piece) (number of digits of ) (number of digits of ), and that length must not exceed . All messages are sent, including any whose piece is empty.
For example, take and the 29 character string floccinaucinihilipilification. At least 20 messages are needed: fl_1/20, oc_2/20, ci_3/20, ..., i_10/20, ..., n_20/20, where the first nine carry two characters each and the last eleven carry one each.
Given and , find the minimum number of messages.
Input
The first and only line contains two integers and separated by a space. (, )
is the maximum length of one message and is the length of the string Cathy wants to send.
Output
Print the minimum number of messages Cathy has to send. If no number of messages can carry the string, print -1 instead.