AtCoder Beginner Contest 259 - A - Growth Record

Time Limit: 2 sec / Memory Limit: 1024 MB

Score : 100100 points

Problem Statement

Takahashi had his NN-th birthday, when he was TT centimeters tall.
Additionally, we know the following facts:

  • In each year between Takahashi's birth (00-th birthday) and his XX-th birthday, his height increased by DD centimeters. More formally, for each i=1,2,,Xi = 1, 2, \ldots, X, his height increased by DD centimeters between his (i1)(i-1)-th birthday and his ii-th birthday.
  • Between Takahashi's XX-th birthday and his NN-th birthday, his height did not change.

Find Takahashi's height on his MM-th birthday, in centimeters.

Constraints

  • 0M<N1000 \leq M \lt N \leq 100
  • 1XN1 \leq X \leq N
  • 1T2001 \leq T \leq 200
  • 1D1001 \leq D \leq 100
  • Takahashi was at least 11 centimeter tall at his birth.
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

NN MM XX TT DD

Output

Print the answer as an integer.


Sample Input 1

1
38 20 17 168 3

Sample Output 1

168

In this sample, Takahashi was 168168 centimeters tall on his 3838-th birthday. Also, his height did not change between his 1717-th birthday and 3838-th birthday.
From these facts, we find that he was 168168 centimeters tall on his 2020-th birthday, so the answer is 168168.


Sample Input 2

1
1 0 1 3 2

Sample Output 2

1
1

In this sample, Takahashi was 11 centimeter tall on his 0(=M)0(=M)-th birthday and 3(=T)3(=T) centimeters tall on his 1(=N)1(=N)-st birthday.


Sample Input 3

1
100 10 100 180 1

Sample Output 3

1
90

题目大意

高橋君$N$岁时身高为$T$,在$X$岁之前,每年长$D$厘米。($X\sim N$岁就不长了)

问高橋君$M$岁时多高。

解题思路

题目保证了$X < N$,也就是说现在高橋君的身高就是他的最终身高(已经不长了)

因此,对于询问的$M$,如果$M\geq X$,那么就输出高橋君的最终身高;否则看从$M$到$X$有几年,就说明长了几个$D$,用最终身高减去$X-M$个$D$即可。


AC代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include <bits/stdc++.h>
using namespace std;
#define mem(a) memset(a, 0, sizeof(a))
#define dbg(x) cout << #x << " = " << x << endl
#define fi(i, l, r) for (int i = l; i < r; i++)
#define cd(a) scanf("%d", &a)
typedef long long ll;
int main() {
int n, m, x, t, d;
cin >> n >> m >> x >> t >> d;
if (m >= x) {
cout << t << endl;
}
else {
int diffYear = x - m;
cout << t - d * diffYear << endl;
}
return 0;
}

同步发文于CSDN,原创不易,转载请附上原文链接哦~
Tisfy:https://letmefly.blog.csdn.net/article/details/125699180


AtCoder Beginner Contest 259 - A - Growth Record
https://blog.letmefly.xyz/2022/07/09/AtCoder Beginner Contest 259 - A - Growth Record/
作者
Tisfy
发布于
2022年7月9日
许可协议