CitadelOA #9
Max Earnings with Schedule Changes
Estimated MediumJudge-ready
Topics (AI-labelled)Greedy
A workday earns fixedPay, plus an extra bonus if the previous day was also a workday. You may change at most k rest days 0 into workdays 1; existing workdays cannot be removed. Find the maximum income. In the original example 100101, changing two days can give 111101; the old explanation missed one digit, and the correct income is 29.
Input
The first line contains n k fixedPay bonus, and the second line contains a 01 string; complete OCR bounds 1≤k≤n≤200000, 1≤fixedPay,bonus≤10^9.
Output
Output a single integer, the answer.
Example 1
Input:
5 2 1 2
10100
Output:
10
Example 2
Input:
6 2 4 3
100101
Output:
29
Example 3
Input:
7 1 3 3
1111001
Output:
30
Example notes
The outputs of the three public examples are, in order: 10; 29; 30. These answers were verified by independent enumeration or direct simulation.
Editorial
Loading solution…