There are *M* male students, *N* female students, and a teacher in a classroom.

The teacher wants to compute the total amount of money in the classroom by a "reduction" procedure.

A student tells his/her amount of money to another student (or to the teacher).

The receiver computes the sum, and relay the information to the next receiver.

For the reduction procedure:

Everyone can only speak to one person, everyone can only listen to one person,

and no one can speak and listen at the same time.

It takes *A* seconds for a female student to tell a number, and *B* seconds for a male student.

Given *A, B, N, M*, find the least time if there is a way to do this.

There are four numbers *A, B, N, M*. For all test cases, 1<=*A*<*B*<=10000 and 0<=*N,M*<=200

Output the least amount of time.

3 5 2 1

8

原TIOJ1534 / ACP 2009 期末考前練習。 Problem setter: Tmt.

No. | Testdata Range | Score |
---|---|---|

1 | 0 | 7 |

2 | 1 | 7 |

3 | 2 | 7 |

4 | 3 | 7 |

5 | 4 | 7 |

6 | 5 | 7 |

7 | 6 | 7 |

8 | 7 | 7 |

9 | 8 | 7 |

10 | 9 | 7 |

11 | 10 | 7 |

12 | 11 | 7 |

13 | 12 | 16 |

No. | Time Limit (ms) | Memory Limit (KiB) | Output Limit (KiB) | Subtasks |
---|---|---|---|---|

0 | 5000 | 65536 | 262144 | |

1 | 5000 | 65536 | 262144 | |

2 | 5000 | 65536 | 262144 | |

3 | 5000 | 65536 | 262144 | |

4 | 5000 | 65536 | 262144 | |

5 | 5000 | 65536 | 262144 | |

6 | 5000 | 65536 | 262144 | |

7 | 5000 | 65536 | 262144 | |

8 | 5000 | 65536 | 262144 | |

9 | 5000 | 65536 | 262144 | |

10 | 5000 | 65536 | 262144 | |

11 | 5000 | 65536 | 262144 | |

12 | 5000 | 65536 | 262144 |