Official

A - Growth Record Editorial by en_translator


If you are new to learning programming and do not know where to start, please try Problem A “Welcome to AtCoder” from practice contest. There you can find a sample code for each language.
Also, if you are not familiar with problems in programming contests, we recommend you to try some problems in “AtCoder Beginners Selection” (https://atcoder.jp/contests/abs).
「競プロ典型 90 問」(Typical 90 Problems of Competitive Programming) (https://atcoder.jp/contests/typical90) is a collection of typical 90 competitive programming problems; unfortunately, currently the problem statements are all Japanese.
「C++入門 AtCoder Programming Guide for beginners (APG4b)」(https://atcoder.jp/contests/APG4b) is a C++ tutorial for competitive programmers. Sadly, this is only in Japanese too.


The Problem Statement says that his height did not change between his \(X\)-th and his \(N\)-th birthday. With the fact that he was \(T\) centimeters tall on his \(N\)-th birthday, we can see that the answer for \(M\geq X\) is \(T\).
If \(M \lt X\), you need to calculate backward his height on his \(M\)-th birthday based on the description that his height did not reach \(T\) centimeters and increased by \(D\) centimeters per year. There are many ways to find out, but one idea is that the height decreases by \(D\) centimeter when we date back by one year. This way, the desired value can be expressed by \(T - (X-M)\times D\).
The program that carries out the computation above and outputs the answer can be written using input/output, arithmetic operations, and conditional branches. The following is a sample code in C++.

#include <bits/stdc++.h>
using namespace std;

int main() {
    
	int N,M,X,T,D;
	cin>>N>>M>>X>>T>>D;

	if(M>=X)cout<<T<<endl;
	else cout<<T-(X-M)*D<<endl;

	return 0;
	
}

posted:
last update: