A - Path to the Target Score
【题目来源】
AtCoder:A - Path to the Target Score
【题目描述】
Takahashi is playing an online game. His current score is \(A\) points. To reach the top of the rankings, he needs a score of at least \(B\) points.
高桥正在玩一款在线游戏。他当前的得分是 \(A\) 分。为了达到排行榜顶端,他需要至少 \(B\) 分。
The only way for Takahashi to increase his score is by purchasing "Score Boosters" from the in-game item shop. Each Score Booster costs \(C\) coins, and each one purchased increases his score by \(1\) point. He can purchase any number of Score Boosters, including \(0\).
高桥提高得分的唯一方法是从游戏内物品商店购买"得分加成器"。每个得分加成器售价 \(C\) 枚金币,每购买一个会将他的得分提高 \(1\) 分。他可以购买任意数量的得分加成器,包括 \(0\) 个。
Find the minimum number of coins required to bring Takahashi's score to at least \(B\) points.
求将高桥的得分提高到至少 \(B\) 分所需的最少金币数量。
Note that if his current score is already at least \(B\) points, he does not need to purchase any Score Boosters, so the answer is \(0\).
注意,如果他当前的得分已经至少是 \(B\) 分,他就不需要购买任何得分加成器,因此答案是 \(0\)。
【输入】
\(A\) \(B\) \(C\)
A single line contains Takahashi's current score \(A\), the minimum score \(B\) required to reach the top of the rankings, and the price \(C\) per Score Booster, separated by spaces.
【输出】
Print on a single line the minimum number of coins required to bring Takahashi's score to at least \(B\) points.
Note that the answer may be as large as approximately \(10^{18}\).
【输入样例】
50 100 3
【输出样例】
150
【解题思路】

【代码详解】
#include <bits/stdc++.h>
using namespace std;
#define int long long
int a, b, c; // a: 初始值,b: 目标值,c: 单位成本signed main()
{cin >> a >> b >> c; // 读入初始值、目标值和单位成本if (b >= a) // 如果目标值大于等于初始值{cout << (b - a) * c; // 计算差值乘以单位成本}else{cout << 0; // 如果目标值小于初始值,输出0}return 0;
}
【运行结果】
50 100 3
150
