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 nn kilos of potatoes for a month. You know that on the first day of the month 11 kilo of potatoes costs aa coins, and on the second day bb 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 mm kilos of potatoes you buy, you get 11 kilo as a gift! In other words, you can get m+1m + 1 kilograms by paying for mm kilograms.

Find the minimum number of coins that you have to spend to buy at least nn kilos of potatoes.

著名超市“第二食品”每月仅营业两天,且这两天的价格各不相同。你希望在一个月内购买 nn 千克土豆。已知该月第一天 1 千克土豆售价为 aa 枚金币,第二天则为 bb 枚金币。“第二食品”允许你购买任意整数千克的土豆。

幸运的是,“第二食品”针对土豆推出了一项仅在该月第一天有效的促销活动:每购买 mm 千克土豆,即可获赠 1 千克!换言之,你只需支付 mm 千克的钱,便可获得 m+1m + 1 千克土豆。

求购买至少 nn 千克土豆所需的最少金币数。

输入格式

Each test contains multiple test cases. The first line contains the number of test cases tt (1≤t≤10 0001 \le t \le 10\,000). Description of the test cases follows.

The first line of each test case contains two integers aa and bb (1≤a,b≤109)(1 \leq a, b \leq 10^9) — the prices of 11 kilo of potatoes on the first and second days, respectively.

The second line contains two integers nn and mm (1≤n,m≤109)(1 \leq n, m \leq 10^9) — the required amount of potatoes to buy and the amount of potatoes to use the promotion.

每个测试包含多个测试用例。第一行包含测试用例的数量 tt(1≤t≤10 0001 \le t \le 10\,000)。随后是各测试用例的描述。

每个测试用例的第一行包含两个整数 aa 和 bb(1≤a,b≤1091 \leq a, b \leq 10^9)——分别为第一天和第二天每千克土豆的价格。

每个测试用例的第二行包含两个整数 nn 和 mm(1≤n,m≤1091 \leq n, m \leq 10^9)——分别为需要购买的土豆总量以及使用促销所需达到的土豆数量。

输出格式

For each test case print one integer — the minimum number of coins that you have to pay to buy at least nn kilos of potatoes.

对于每个测试用例,输出一个整数——购买至少 nn 千克土豆所需的最少硬币数。

输入输出样例

  • 输入#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 11 kilo and get 11 more for a promotion. On the second day, you can buy 11 kilo of potatoes. Thus, you will spend 5+4=95+4=9 coins in total.

In the second test case, on the first day you buy 22 kilo and get another 11 more for a promotion. This way you will spend 2⋅5=102 \cdot 5 = 10 coins.

在第一个测试用例中,第一天你购买 11 千克,并因促销活动额外获得 11 千克;第二天你可以购买 11 千克土豆。因此,你总共将花费 5+4=95+4=9 枚金币。

在第二个测试用例中,第一天你购买 22 千克,并因促销活动额外获得 11 千克。这样你将花费 2⋅5=102 \cdot 5 = 10 枚金币。

输入解题思路,AI测评打分。不知道怎么写?

首页