Shomtring
Time limit2sMemory limit128 MB
Given limits on total A's, total B's, and the longest allowed run of each, compute the maximum length string built only from A and B.
- Level
Medium6 of 10
- Topics
- Greedy, Math, Implementation
- Solved
- No attempts yet
Problem
A string made only of the characters A and B is called a Shomtring if it satisfies all of the following conditions.
- It uses at most
countAcharactersA. - It uses at most
countBcharactersB. - Every contiguous block made only of
Ahas length at mostmaxA. - Every contiguous block made only of
Bhas length at mostmaxB.
Given countA, countB, maxA, and maxB, find the maximum possible length of a Shomtring.
Input
The first line contains four integers countA, countB, maxA, and maxB. Each value is between 0 and 1,000,000, inclusive.
Output
Print the maximum possible length of a Shomtring.