Christmas digits
Practice
3.8 (6 votes)
Dynamic programming
Algorithms
Approved
Medium
Problem
90% Success 3231 Attempts 30 Points 1s Time Limit 256MB Memory 1024 KB Max Code

Little Santa made a list of all the naughty children. He created a programming problem and he will give gift to only those naughty children who will solve that problem. The problem is:

Given three integers, \(n, k, x\) (without leading zeros), you can insert at most k digits at any positions in n. You have to create the maximum number (without leading zeros) from n which is not greater than x.

enter image description here

All the children want gifts so they asked you to solve the problem for them.

Input format:
First line of input contains three integers, \(n, k, x\) \((1 <= n <= x <= 10^{100000})\), \((0 <= k <= 100000)\).

Output format:
Print one integer, denoting the maximum number (without leading zeros) that can be created from n which is not greater than x after inserting at most k digits at any position in n.

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:30
Tags:
Medium
Points:30
58 votes
Tags:
ReadyMathematicsDynamic ProgrammingMedium
Points:30
9 votes
Tags:
Dynamic ProgrammingCombinatoricsMediumMathematicsOpenApproved