Official

A - Don't be late Editorial by evima


In order to find whether Takahashi can arrive there in \(T\) minutes, find how many minutes does it take for Takahashi to arrive there, then all you have to do is doing a comparison.

The amount of time until Takaashi arrives will not be an integer. In most languages, divisions between integers results in integers, the decimal part of which is rounded down. In this problem, you cannot obtain the right answer if the answer is rounded down, for example when D = 11, T = 5 and S = 2.

Here, if you calculate them as decimal numbers using types like double, the result will not have precision errors in this problem, so you can solve it correctly. (The explanation of the precision errors)

Sample Code(C++)

#include <iostream>
using namespace std;

int main() {
	//Recieve the inputs
	int D, T, S;
	cin >> D >> T >> S;

	//Calculate the duration of Takahashi's journey
	double time = (double)D / S;

	//Output depending on the inequality between T and time
	if (T >= time) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}


Although it is not required in this problem, if the results of intermediate operations are decimals, the answer may be slightly different from the true value even if the ultimate result should be an integer.

For example, when calculating 1 / 3 * 3, the intermediate result of 1 / 3 will be 0.3333, and therefore three times that value will be like 0.9999. (If you want more strict discussion, search for “floating point numbers” or “floating point operations”)

To avoid this, it may be better choice to prefer not to use decimals for the future problem.

In this problem, instead of finding how many minutes he needs to arrive, calculate how many meters he can travel in \(T\) minutes, then the operation of division is substituted by multiplication, and therefore can be solved only by integer operations. If the distance he can travel is at least D meters, then Takahashi will be able to arrive in time.

Samplce Code(C++)

#include <iostream>
using namespace std;

int main() {
	//Recieve the inputs
	int D, T, S;
	cin >> D >> T >> S;

	//Calculate the possible distance of Takahashi's travel
	int dist = S * T;

	//Output depending on the inequality between D and dist
	if (dist >= D) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}


posted:
last update: