#abc332b. B - Glass and Mug

B - Glass and Mug

Score : 200200 points

问题描述

AtCoder Inc. 出售玻璃杯马克杯

高桥拥有一个容量为 GG 毫升的玻璃杯和一个容量为 MM 毫升的马克杯。这里,G<MG<M

最初,玻璃杯和马克杯都是空的。在执行以下操作 KK 次后,确定玻璃杯和马克杯中分别有多少毫升的水。

  • 当玻璃杯装满水,即玻璃杯内恰好含有 GG 毫升水时,将玻璃杯中的所有水倒掉。
  • 否则,如果马克杯是空的,则将马克杯装满水。
  • 否则,将马克杯中的水转移至玻璃杯,直到马克杯变空或玻璃杯装满水为止。

以上为通义千问 qwen-max 翻译,仅供参考。

Problem Statement

AtCoder Inc. sells glasses and mugs.

Takahashi has a glass with a capacity of GG milliliters and a mug with a capacity of MM milliliters.
Here, G<MG<M.

Initially, both the glass and the mug are empty.
After performing the following operation KK times, determine how many milliliters of water are in the glass and the mug, respectively.

  • When the glass is filled with water, that is, the glass contains exactly GG milliliters of water, discard all the water from the glass.
  • Otherwise, if the mug is empty, fill the mug with water.
  • Otherwise, transfer water from the mug to the glass until the mug is empty or the glass is filled with water.

Constraints

  • 1K1001\leq K\leq 100
  • 1G<M10001\leq G<M\leq 1000
  • GG, MM, and KK are integers.

Input

The input is given from Standard Input in the following format:

KK GG MM

Output

Print the amounts, in milliliters, of water in the glass and the mug, in this order, separated by a space, after performing the operation KK times.

Sample Input 1

5 300 500

Sample Output 1

200 500

The operation will be performed as follows. Initially, both the glass and the mug are empty.

  • Fill the mug with water. The glass has 00 milliliters, and the mug has 500500 milliliters of water.
  • Transfer water from the mug to the glass until the glass is filled. The glass has 300300 milliliters, and the mug has 200200 milliliters of water.
  • Discard all the water from the glass. The glass has 00 milliliters, and the mug has 200200 milliliters of water.
  • Transfer water from the mug to the glass until the mug is empty. The glass has 200200 milliliters, and the mug has 00 milliliters of water.
  • Fill the mug with water. The glass has 200200 milliliters, and the mug has 500500 milliliters of water.

Thus, after five operations, the glass has 200200 milliliters, and the mug has 500500 milliliters of water. Hence, print 200200 and 500500 in this order, separated by a space.

Sample Input 2

5 100 200

Sample Output 2

0 0

update @ 2024/3/10 01:17:03