{"problem":{"name":"A. Feed the cat","description":{"content":"After waking up at _hh_:_mm_, Andrew realised that he had forgotten to feed his only cat for yet another time (guess why there's only one cat). The cat's current hunger level is _H_ points, moreover e","description_type":"Markdown"},"platform":"Codeforces","limit":{"time_limit":1000,"memory_limit":262144},"difficulty":"None","is_remote":true,"is_sync":true,"sync_url":null,"sign":"CF955A"},"statements":[{"statement_type":"Markdown","content":"After waking up at _hh_:_mm_, Andrew realised that he had forgotten to feed his only cat for yet another time (guess why there's only one cat). The cat's current hunger level is _H_ points, moreover each minute without food increases his hunger by _D_ points.\n\nAt any time Andrew can visit the store where tasty buns are sold (you can assume that is doesn't take time to get to the store and back). One such bun costs _C_ roubles and decreases hunger by _N_ points. Since the demand for bakery drops heavily in the evening, there is a special 20% discount for buns starting from 20:00 (note that the cost might become rational). Of course, buns cannot be sold by parts.\n\nDetermine the minimum amount of money Andrew has to spend in order to feed his cat. The cat is considered fed if its hunger level is less than or equal to zero.\n\n## Input\n\nThe first line contains two integers _hh_ and _mm_ (00 ≤ _hh_ ≤ 23, 00 ≤ _mm_ ≤ 59) — the time of Andrew's awakening.\n\nThe second line contains four integers _H_, _D_, _C_ and _N_ (1 ≤ _H_ ≤ 105, 1 ≤ _D_, _C_, _N_ ≤ 102).\n\n## Output\n\nOutput the minimum amount of money to within three decimal digits. You answer is considered correct, if its absolute or relative error does not exceed 10 - 4.\n\nFormally, let your answer be _a_, and the jury's answer be _b_. Your answer is considered correct if .\n\n[samples]\n\n## Note\n\nIn the first sample Andrew can visit the store at exactly 20:00. The cat's hunger will be equal to 315, hence it will be necessary to purchase 315 buns. The discount makes the final answer 25200 roubles.\n\nIn the second sample it's optimal to visit the store right after he wakes up. Then he'll have to buy 91 bins per 15 roubles each and spend a total of 1365 roubles.","is_translate":false,"language":"English"},{"statement_type":"Markdown","content":"在 #cf_span[hh]:#cf_span[mm] 醒来后，Andrew 意识到他又一次忘记了喂他唯一的猫（猜猜为什么只有一只猫）。猫当前的饥饿值为 #cf_span[H] 点，且每分钟没有食物，饥饿值会增加 #cf_span[D] 点。\n\nAndrew 可以在任何时间前往出售美味面包的商店（可以假设前往商店并返回不需要时间）。一个这样的面包售价 #cf_span[C] 卢布，可使饥饿值减少 #cf_span[N] 点。由于晚上烘焙产品需求大幅下降，从 #cf_span[20]:#cf_span[00] 开始，面包享有 #cf_span[20%] 的特殊折扣（注意价格可能变为有理数）。当然，面包不能分割出售。\n\n请确定 Andrew 为喂饱猫所需的最少花费。当猫的饥饿值小于或等于零时，视为已喂饱。\n\n第一行包含两个整数 #cf_span[hh] 和 #cf_span[mm] #cf_span[(00 ≤ hh ≤ 23, 00 ≤ mm ≤ 59)] —— Andrew 醒来的时刻。\n\n第二行包含四个整数 #cf_span[H], #cf_span[D], #cf_span[C] 和 #cf_span[N] #cf_span[(1 ≤ H ≤ 105, 1 ≤ D, C, N ≤ 102)]。\n\n请输出最少花费，保留三位小数。你的答案被认为是正确的，当且仅当其绝对误差或相对误差不超过 #cf_span[10 - 4]。\n\n形式上，设你的答案为 #cf_span[a]，评测标准答案为 #cf_span[b]。你的答案被认为是正确的，当且仅当 。\n\n在第一个样例中，Andrew 可以在恰好 #cf_span[20]:#cf_span[00] 前往商店。此时猫的饥饿值为 #cf_span[315]，因此需要购买 #cf_span[315] 个面包。折扣使最终答案为 #cf_span[25200] 卢布。\n\n在第二个样例中，最优策略是在他醒来后立即前往商店。此时他需要购买 #cf_span[91] 个面包，每个 #cf_span[15] 卢布，总共花费 #cf_span[1365] 卢布。\n\n## Input\n\n第一行包含两个整数 #cf_span[hh] 和 #cf_span[mm] #cf_span[(00 ≤ hh ≤ 23, 00 ≤ mm ≤ 59)] —— Andrew 醒来的时刻。第二行包含四个整数 #cf_span[H], #cf_span[D], #cf_span[C] 和 #cf_span[N] #cf_span[(1 ≤ H ≤ 105, 1 ≤ D, C, N ≤ 102)]。\n\n## Output\n\n请输出最少花费，保留三位小数。你的答案被认为是正确的，当且仅当其绝对误差或相对误差不超过 #cf_span[10 - 4]。形式上，设你的答案为 #cf_span[a]，评测标准答案为 #cf_span[b]。你的答案被认为是正确的，当且仅当 。\n\n[samples]\n\n## Note\n\n在第一个样例中，Andrew 可以在恰好 #cf_span[20]:#cf_span[00] 前往商店。此时猫的饥饿值为 #cf_span[315]，因此需要购买 #cf_span[315] 个面包。折扣使最终答案为 #cf_span[25200] 卢布。在第二个样例中，最优策略是在他醒来后立即前往商店。此时他需要购买 #cf_span[91] 个面包，每个 #cf_span[15] 卢布，总共花费 #cf_span[1365] 卢布。","is_translate":true,"language":"Chinese"},{"statement_type":"Markdown","content":"**Definitions**  \nLet $ t_{\\text{awake}} = 60 \\cdot hh + mm $ be the time (in minutes since midnight) when Andrew wakes up.  \nLet $ t_{\\text{discount}} = 20 \\cdot 60 = 1200 $ be the time (in minutes since midnight) when the 20% discount starts.  \n\nLet:  \n- $ H \\in \\mathbb{Z}^+ $: initial hunger level of the cat.  \n- $ D \\in \\mathbb{Z}^+ $: hunger increase per minute.  \n- $ C \\in \\mathbb{Z}^+ $: base cost of one bun (in roubles).  \n- $ N \\in \\mathbb{Z}^+ $: hunger reduction per bun.  \n\nLet $ c_{\\text{discount}} = 0.8 \\cdot C $ be the discounted cost per bun.  \n\nLet $ k \\in \\mathbb{Z}^+ $ be the number of buns purchased.  \n\n**Constraints**  \n1. $ 0 \\le hh \\le 23 $, $ 0 \\le mm \\le 59 $  \n2. $ 1 \\le H \\le 10^5 $, $ 1 \\le D, C, N \\le 10^2 $  \n\n**Objective**  \nAndrew may choose to buy buns at any time $ t \\ge t_{\\text{awake}} $.  \nAt time $ t $, the cat’s hunger is:  \n$$\nH(t) = H + D \\cdot (t - t_{\\text{awake}})\n$$  \n\nTo feed the cat, we require:  \n$$\nH(t) - N \\cdot k \\le 0 \\quad \\Rightarrow \\quad k \\ge \\left\\lceil \\frac{H + D \\cdot (t - t_{\\text{awake}})}{N} \\right\\rceil\n$$  \n\nThe cost depends on whether $ t \\ge t_{\\text{discount}} $:  \n- If $ t < t_{\\text{discount}} $: cost = $ k \\cdot C $  \n- If $ t \\ge t_{\\text{discount}} $: cost = $ k \\cdot c_{\\text{discount}} $  \n\nAndrew can choose to buy immediately at $ t = t_{\\text{awake}} $, or wait until $ t = t_{\\text{discount}} $ (or later), but waiting only increases hunger (and thus required buns), while potentially lowering per-bun cost.  \n\n**Optimization Goal**  \nMinimize total cost over two candidate strategies:  \n1. Buy immediately at $ t = t_{\\text{awake}} $:  \n   $$\n   k_1 = \\left\\lceil \\frac{H}{N} \\right\\rceil, \\quad \\text{cost}_1 = k_1 \\cdot C\n   $$  \n2. Wait until discount starts at $ t = t_{\\text{discount}} $ (if $ t_{\\text{discount}} > t_{\\text{awake}} $):  \n   $$\n   H_{\\text{delay}} = H + D \\cdot (t_{\\text{discount}} - t_{\\text{awake}}), \\quad k_2 = \\left\\lceil \\frac{H_{\\text{delay}}}{N} \\right\\rceil, \\quad \\text{cost}_2 = k_2 \\cdot c_{\\text{discount}}\n   $$  \n\nIf $ t_{\\text{discount}} \\le t_{\\text{awake}} $, then discount is already active, so only strategy 2 applies (with $ H_{\\text{delay}} = H $).  \n\n**Final Objective**  \n$$\n\\min \\left( \\text{cost}_1, \\text{cost}_2 \\right)\n$$  \nwhere $ \\text{cost}_2 $ is only defined if $ t_{\\text{discount}} \\ge t_{\\text{awake}} $.  \n\nOutput the minimum cost as a real number, rounded to three decimal places.","is_translate":false,"language":"Formal"}],"meta":{"iden":"CF955A","tags":["greedy","math"],"sample_group":[["19 00\n255 1 100 1","25200.0000"],["17 41\n1000 6 15 11","1365.0000"]],"created_at":"2026-03-03 11:00:39"}}