Problem · Array
Maximize Workday Earnings
Learn this problemProblem statement
You are given a work schedule schedule. Each character is W for a workday or O for a day off.
- Every workday earns
dailyPay. - A workday also earns
consecutiveBonuswhen the immediately preceding day is a workday. - You may change at most
koccurrences ofOintoW.
Return the maximum total earnings after the changes. Both pay values are nonnegative, so changing an additional available day off can never reduce the result.
Function
maximizeEarnings(schedule: String, k: int, dailyPay: long, consecutiveBonus: long) → longExamples
Example 1
schedule = "WOWO"k = 1dailyPay = 10consecutiveBonus = 5return = 40Changing the middle day off produces WWWO. Three workdays earn 30, and the two adjacent workday pairs earn 10 in bonuses.
Example 2
schedule = "OOOO"k = 2dailyPay = 10consecutiveBonus = 5return = 25Choose two adjacent days. The two workdays earn 20, and their one adjacency earns a bonus of 5.
Example 3
schedule = "WWOOOW"k = 2dailyPay = 10consecutiveBonus = 5return = 65Use both changes next to the leading run, producing four consecutive workdays and one separated workday. Five workdays earn 50, and three adjacencies earn 15.
Constraints
1 <= schedule.length <= 200000schedule[i]isWorO.0 <= k <= schedule.length0 <= dailyPay, consecutiveBonus <= 10^9- The answer fits in a signed 64-bit integer.