Official

A - 目標スコアへの道 / Path to the Target Score Editorial by admin

Gemini 3.0 Flash

Overview

This problem asks you to calculate the minimum cost of buying “score boosters” (each costing \(C\) coins per point) to raise your current score \(A\) to at least the target score \(B\).

Analysis

This problem can be divided into two main patterns depending on Takahashi’s current situation:

  1. Already achieved the target (\(A \geq B\)) In this case, there is no need to increase the score further. Therefore, the number of coins needed is \(0\).
  2. Target not yet reached (\(A < B\)) We need to consider how many more points are needed to reach the target score \(B\). The required score is \(B - A\) points. Since each score booster increases the score by 1 point and costs \(C\) coins, a total of \((B - A) \times C\) coins is needed.

Checking the constraints, \(A, B, C\) can each be up to \(10^9\). Since the score deficit \((B-A)\) can be up to \(10^9\) and the price \(C\) can also be up to \(10^9\), the answer can reach up to \(10^9 \times 10^9 = 10^{18}\). In languages like Python that handle arbitrary-precision integers, this is not an issue, but in languages like C++, note that you need to use the long long type (64-bit integer).

Algorithm

Use conditional branching (if statement) to handle the two cases based on whether the current score already meets the target.

  1. Read input \(A, B, C\).
  2. If \(A \geq B\), output 0.
  3. Otherwise, compute and output \((B - A) \times C\).

Complexity

  • Time complexity: \(O(1)\)
    • Only numerical input, a few arithmetic operations, and comparisons are performed, so the execution time is constant regardless of the input size.
  • Space complexity: \(O(1)\)
    • Only memory for storing the variables \(A, B, C\) is needed, which is constant.

Implementation Notes

  • Simplifying the conditional: By using the expression max(0, B - A) * C, it is possible to write the logic “if \(A\) is greater than \(B\), use \(0\)” in a single line without an if statement.

  • Handling large numbers: Since the answer can become very large, care must be taken to avoid overflow. In Python, large integers are handled natively, so no special measures are needed to get the correct answer.

    Source Code

import sys

def solve():
    # 入力を標準入力から読み込む
    input_data = sys.stdin.read().split()
    if not input_data:
        return
    
    a = int(input_data[0])
    b = int(input_data[1])
    c = int(input_data[2])
    
    # 現在のスコアが目標スコア以上の場合は0
    if a >= b:
        print(0)
    else:
        # 不足しているスコア分だけアイテムを購入する
        needed_points = b - a
        total_cost = needed_points * c
        print(total_cost)

if __name__ == '__main__':
    solve()

This editorial was generated by gemini-3-flash-preview.

posted:
last update: