/
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 150 点
問題文
高橋君は学校でゲームを楽しんでいます。チャイムが鳴ると同時にゲームが開始します。
高橋君はチャイムが鳴った直後から、以下の動作を繰り返し行います。
- 毎秒 S メートルの速さで A 秒間走る。その後の B 秒間は静止する。
チャイムが鳴ってから X 秒が経過するまでに、高橋君は合計何メートル走りますか?
制約
- 1 \leq S \leq 15
- 1 \leq A \leq 1000
- 1 \leq B \leq 1000
- 1 \leq X \leq 1000
- 入力される値はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
S A B X
出力
答えを 1 行に出力せよ。単位 (メートル) は省いて出力すること。
入力例 1
7 3 2 11
出力例 1
49
チャイムが鳴ってからの 11 秒間、高橋君は以下のように動きます。
- 0 秒後から 3 秒後までのあいだ、高橋君は毎秒 7 メートルの速さで走る。このあいだの移動距離は 21 メートル。
- 3 秒後から 5 秒後までのあいだ、高橋君は静止する。
- 5 秒後から 8 秒後までのあいだ、高橋君は毎秒 7 メートルの速さで走る。このあいだの移動距離は 21 メートル。
- 8 秒後から 10 秒後までのあいだ、高橋君は静止する。
- 10 秒後から 11 秒後までのあいだ、高橋君は毎秒 7 メートルの速さで走る。このあいだの移動距離は 7 メートル。
総移動距離は 49 メートルなので、49 を出力します。
入力例 2
6 3 2 9
出力例 2
36
チャイムが鳴ってからの 9 秒間、高橋君は以下のように動きます。
- 0 秒後から 3 秒後までのあいだ、高橋君は毎秒 6 メートルの速さで走る。このあいだの移動距離は 18 メートル。
- 3 秒後から 5 秒後までのあいだ、高橋君は静止する。
- 5 秒後から 8 秒後までのあいだ、高橋君は毎秒 6 メートルの速さで走る。このあいだの移動距離は 18 メートル。
- 8 秒後から 9 秒後までのあいだ、高橋君は静止する。
総移動距離は 36 メートルなので、36 を出力します。
入力例 3
1 1 666 428
出力例 3
1
チャイムが鳴ってからの 428 秒間、高橋君は以下のように動きます。
- 0 秒後から 1 秒後までのあいだ、高橋君は毎秒 1 メートルの速さで走る。このあいだの移動距離は 1 メートル。
- 1 秒後から 428 秒後までのあいだ、高橋君は静止する。
総移動距離は 1 メートルなので、1 を出力します。
Score : 150 points
Problem Statement
Takahashi is enjoying a game at school. The game starts at the moment the bell rings.
Immediately after the bell rings, he repeats the following actions:
- Run at a speed of S meters per second for A seconds. Then, remain stationary for B seconds.
How many meters in total does he run by the time X seconds have elapsed since the bell rang?
Constraints
- 1 \leq S \leq 15
- 1 \leq A \leq 1000
- 1 \leq B \leq 1000
- 1 \leq X \leq 1000
- All input values are integers.
Input
The input is given from Standard Input in the following format:
S A B X
Output
Output the answer in one line. Omit the unit (meters) in the output.
Sample Input 1
7 3 2 11
Sample Output 1
49
During the 11 seconds after the bell rings, Takahashi moves as follows:
- From 0 seconds to 3 seconds, he runs at a speed of 7 meters per second. The distance traveled during this time is 21 meters.
- From 3 seconds to 5 seconds, he remains stationary.
- From 5 seconds to 8 seconds, he runs at a speed of 7 meters per second. The distance traveled during this time is 21 meters.
- From 8 seconds to 10 seconds, he remains stationary.
- From 10 seconds to 11 seconds, he runs at a speed of 7 meters per second. The distance traveled during this time is 7 meters.
The total distance traveled is 49 meters, so output 49.
Sample Input 2
6 3 2 9
Sample Output 2
36
During the 9 seconds after the bell rings, Takahashi moves as follows:
- From 0 seconds to 3 seconds, he runs at a speed of 6 meters per second. The distance traveled during this time is 18 meters.
- From 3 seconds to 5 seconds, he remains stationary.
- From 5 seconds to 8 seconds, he runs at a speed of 6 meters per second. The distance traveled during this time is 18 meters.
- From 8 seconds to 9 seconds, he remains stationary.
The total distance traveled is 36 meters, so output 36.
Sample Input 3
1 1 666 428
Sample Output 3
1
During the 428 seconds after the bell rings, Takahashi moves as follows:
- From 0 seconds to 1 second, he runs at a speed of 1 meter per second. The distance traveled during this time is 1 meter.
- From 1 second to 428 seconds, he remains stationary.
The total distance traveled is 1 meter, so output 1.