CF1793A.Yet Another Promotion
入门
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
The famous store "Second Food" sells groceries only two days a month. And the prices in each of days differ. You wanted to buy n kilos of potatoes for a month. You know that on the first day of the month 1 kilo of potatoes costs a coins, and on the second day b coins. In "Second Food" you can buy any integer kilograms of potatoes.
Fortunately, "Second Food" has announced a promotion for potatoes, which is valid only on the first day of the month — for each m kilos of potatoes you buy, you get 1 kilo as a gift! In other words, you can get m+1 kilograms by paying for m kilograms.
Find the minimum number of coins that you have to spend to buy at least n kilos of potatoes.
著名超市“第二食品”每月仅营业两天,且这两天的价格各不相同。你希望在一个月内购买 n 千克土豆。已知该月第一天 1 千克土豆售价为 a 枚金币,第二天则为 b 枚金币。“第二食品”允许你购买任意整数千克的土豆。
幸运的是,“第二食品”针对土豆推出了一项仅在该月第一天有效的促销活动:每购买 m 千克土豆,即可获赠 1 千克!换言之,你只需支付 m 千克的钱,便可获得 m+1 千克土豆。
求购买至少 n 千克土豆所需的最少金币数。
输入格式
Each test contains multiple test cases. The first line contains the number of test cases t (1≤t≤10000). Description of the test cases follows.
The first line of each test case contains two integers a and b (1≤a,b≤109) — the prices of 1 kilo of potatoes on the first and second days, respectively.
The second line contains two integers n and m (1≤n,m≤109) — the required amount of potatoes to buy and the amount of potatoes to use the promotion.
每个测试包含多个测试用例。第一行包含测试用例的数量 t(1≤t≤10000)。随后是各测试用例的描述。
每个测试用例的第一行包含两个整数 a 和 b(1≤a,b≤109)——分别为第一天和第二天每千克土豆的价格。
每个测试用例的第二行包含两个整数 n 和 m(1≤n,m≤109)——分别为需要购买的土豆总量以及使用促销所需达到的土豆数量。
输出格式
For each test case print one integer — the minimum number of coins that you have to pay to buy at least n kilos of potatoes.
对于每个测试用例,输出一个整数——购买至少 n 千克土豆所需的最少硬币数。
输入输出样例
输入#1
5 5 4 3 1 5 4 3 2 3 4 3 5 20 15 10 2 1000000000 900000000 1000000000 8
输出#1
9 10 9 135 888888888900000000
说明/提示
In the first test case, on the first day you buy 1 kilo and get 1 more for a promotion. On the second day, you can buy 1 kilo of potatoes. Thus, you will spend 5+4=9 coins in total.
In the second test case, on the first day you buy 2 kilo and get another 1 more for a promotion. This way you will spend 2⋅5=10 coins.
在第一个测试用例中,第一天你购买 1 千克,并因促销活动额外获得 1 千克;第二天你可以购买 1 千克土豆。因此,你总共将花费 5+4=9 枚金币。
在第二个测试用例中,第一天你购买 2 千克,并因促销活动额外获得 1 千克。这样你将花费 2⋅5=10 枚金币。
输入解题思路,AI测评打分。不知道怎么写?