Text Message Fees
Time limit2sMemory limit128 MB
Given a per-message fee and two reusable text-message packs with fixed price and quota, find the minimum cost to send exactly T messages.
- Level
Hard8 of 10
- Topics
- Math, Number theory, Greedy, Implementation
- Solved
- No attempts yet
Problem
Minsik Telecom is a mobile carrier. Under its basic plan, each text message costs 10 won.
The company also sells text-message packs. When a customer buys a pack, they may send a fixed number of text messages without paying the basic per-message fee for those messages. Each kind of pack may be bought any number of times. If the customer sends more messages than the total number covered by purchased packs, every uncovered message is charged at the basic rate.
Youngsik wants to minimize his monthly bill. He sends T text messages in one month. There are two kinds of text-message packs. The first pack costs P1 won and covers K1 messages. The second pack costs P2 won and covers K2 messages. He may buy both kinds of packs, and the total number of messages covered by purchased packs may exceed T.
Input
The first line contains five integers T, K1, P1, K2, and P2.
Output
Output the minimum possible monthly fee.
Constraints
0 <= T <= 10^121 <= K1, K2 <= 10^121 <= P1, P2 <= 10^13P1 <= 20 * K1P2 <= 20 * K2