Maximum profit from sandwiches
You have B slices of bread and F fillings. A plain sandwich uses 2 slices and 1 filling and sells for X; a club sandwich uses 3 slices and 2 fillings and sells for Y. Make any number of each so that the total money is as large as possible.
Reported in: Infosys (SP / DSE · 29 Nov 2026) (memory-based)
Input
One line: B F X Y.
Output
The largest total money.
Constraints
0 ≤ B, F ≤ 10^6; 1 ≤ X, Y ≤ 10^6.
Example 1
Input:
6 4 3 5
Output:
10Example 2
Input:
10 5 4 7
Output:
20Example 3
Input:
5 1 10 20
Output:
10Hint: Try every possible number of club sandwiches c, from 0 to min(B/3, F/2). With the bread and fillings left, make as many plain ones as you can, and keep the best total.