310174: CF1793A. Yet Another Promotion

Memory Limit:256 MB Time Limit:1 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Yet Another Promotion

题意翻译

### 题目描述 共 $t$ 组数据,每组数据中,你需要买 $n$ 公斤苹果,第一天单价为 $a$ ,但每买 $m$ 公斤赠送一公斤;第二天单价为 $b$ 。求最小花费。 ### 输入输出格式 第一行一个正整数 $t$ ,对于每组数据输入包含两行,第一行两个正整数 $a,b$ ,第二行两个正整数 $n,m$ 。\ 对于每组数据,输出一行一个正整数,表示最少花费。 ### 数据范围 $1 \leqslant t \leqslant 10^4 \ , \ 1 \leqslant a,b,n,m \leqslant 10^9$ 。

题目描述

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.

输入输出格式

输入格式


Each test contains multiple test cases. The first line contains the number of test cases $ t $ ( $ 1 \le t \le 10\,000 $ ). Description of the test cases follows. The first line of each test case contains two integers $ a $ and $ b $ $ (1 \leq a, b \leq 10^9) $ — the prices of $ 1 $ kilo of potatoes on the first and second days, respectively. The second line contains two integers $ n $ and $ m $ $ (1 \leq n, m \leq 10^9) $ — the required amount of potatoes to buy and the amount of potatoes to use the promotion.

输出格式


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.

输入输出样例

输入样例 #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 \cdot 5 = 10 $ coins.

Input

题意翻译

### 题目描述 共 $t$ 组数据,每组数据中,你需要买 $n$ 公斤苹果,第一天单价为 $a$ ,但每买 $m$ 公斤赠送一公斤;第二天单价为 $b$ 。求最小花费。 ### 输入输出格式 第一行一个正整数 $t$ ,对于每组数据输入包含两行,第一行两个正整数 $a,b$ ,第二行两个正整数 $n,m$ 。\ 对于每组数据,输出一行一个正整数,表示最少花费。 ### 数据范围 $1 \leqslant t \leqslant 10^4 \ , \ 1 \leqslant a,b,n,m \leqslant 10^9$ 。

Output

**题目描述**

“第二食品店”每个月只卖两天杂货,而且每天的价格都不同。你想为一个星期买 $ n $ 公斤土豆。你知道这个月的第一天,1公斤土豆的价格是 $ a $ 枚硬币,第二天是 $ b $ 枚硬币。在“第二食品店”,你可以买任意整数公斤的土豆。

幸运的是,“第二食品店”宣布了一个只适用于这个月第一天的土豆促销活动——每买 $ m $ 公斤土豆,就可以额外获得1公斤免费!换句话说,你可以通过支付 $ m $ 公斤的价格得到 $ m + 1 $ 公斤。

找出你至少需要花费多少硬币来买至少 $ n $ 公斤土豆的最小数目。

**输入输出格式**

**输入格式**

每个测试包含多个测试案例。第一行包含测试案例的数量 $ t $($ 1 \le t \le 10,000 $)。测试案例的描述如下。

每个测试案例的第一行包含两个整数 $ a $ 和 $ b $($ 1 \le a, b \le 10^9 $)——分别是在第一和第二天1公斤土豆的价格。

第二行包含两个整数 $ n $ 和 $ m $($ 1 \le n, m \le 10^9 $)——需要购买的土豆数量和用于促销的土豆数量。

**输出格式**

对于每个测试案例,打印一个整数——为了买至少 $ 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
```

**说明**

在第一个测试案例中,第一天你买了1公斤土豆,并且因为促销活动额外获得了1公斤。第二天,你可以再买1公斤土豆。因此,你总共将花费 $ 5 + 4 = 9 $ 枚硬币。

在第二个测试案例中,第一天你买了2公斤土豆,并且因为促销活动额外获得了1公斤。这种方式你将花费 $ 2 \times 5 = 10 $ 枚硬币。**题目描述** “第二食品店”每个月只卖两天杂货,而且每天的价格都不同。你想为一个星期买 $ n $ 公斤土豆。你知道这个月的第一天,1公斤土豆的价格是 $ a $ 枚硬币,第二天是 $ b $ 枚硬币。在“第二食品店”,你可以买任意整数公斤的土豆。 幸运的是,“第二食品店”宣布了一个只适用于这个月第一天的土豆促销活动——每买 $ m $ 公斤土豆,就可以额外获得1公斤免费!换句话说,你可以通过支付 $ m $ 公斤的价格得到 $ m + 1 $ 公斤。 找出你至少需要花费多少硬币来买至少 $ n $ 公斤土豆的最小数目。 **输入输出格式** **输入格式** 每个测试包含多个测试案例。第一行包含测试案例的数量 $ t $($ 1 \le t \le 10,000 $)。测试案例的描述如下。 每个测试案例的第一行包含两个整数 $ a $ 和 $ b $($ 1 \le a, b \le 10^9 $)——分别是在第一和第二天1公斤土豆的价格。 第二行包含两个整数 $ n $ 和 $ m $($ 1 \le n, m \le 10^9 $)——需要购买的土豆数量和用于促销的土豆数量。 **输出格式** 对于每个测试案例,打印一个整数——为了买至少 $ 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 ``` **说明** 在第一个测试案例中,第一天你买了1公斤土豆,并且因为促销活动额外获得了1公斤。第二天,你可以再买1公斤土豆。因此,你总共将花费 $ 5 + 4 = 9 $ 枚硬币。 在第二个测试案例中,第一天你买了2公斤土豆,并且因为促销活动额外获得了1公斤。这种方式你将花费 $ 2 \times 5 = 10 $ 枚硬币。

加入题单

算法标签: