#P12146. Minimum Cost to Delete Candies or Cookies
Minimum Cost to Delete Candies or Cookies
Minimum Cost to Delete Candies or Cookies
You are given two types of items: candies and cookies. You have \(a\) candies and \(b\) cookies. You can perform one of the following operations as many times as you wish:
- Operation 1: Choose two candies or two cookies (i.e. a pair of the same type), remove them, at a cost of \(x\). (This operation can be applied only if there are at least two candies or at least two cookies available.)
- Operation 2: Choose one candy and one cookie, remove them, at a cost of \(y\). (This operation can be applied only if there is at least one candy and at least one cookie available.)
Your goal is to remove all candies or all cookies (or both) with the minimum total cost. Determine the minimum cost required to achieve this goal.
inputFormat
The input consists of four space-separated integers: \(a\), \(b\), \(x\), and \(y\), where \(a\) and \(b\) denote the number of candies and cookies respectively, and \(x\) and \(y\) denote the costs of Operation 1 and Operation 2 respectively.
outputFormat
Output a single integer representing the minimum cost required to remove all candies or all cookies (or both).
sample
3 5 10 1
3