A - Supermajority Editorial by en_translator Editorial for printing
For beginners
- 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".
- 「C++入門 AtCoder Programming Guide for beginners (APG4b)」 is a C++ tutorial for competitive programmers. Sadly, this is only in Japanese too.
- 「Python入門 AtCoder Programming Guide for beginners (APG4bPython)」 is a Python tutorial for competitive programmers. Again, this is only in Japanese.
Solution 1
Find the value \(\displaystyle B \times \frac{2}{3}\) as a floating-point number, and compare it with \(A\) to find the answer.
Sample code (Python):
a, b = map(int, input().split())
if (a > b*2/3):
print("Yes")
else:
print("No")
Sample code (C++):
#include <iostream>
using std::cin;
using std::cout;
using std::cerr;
using std::endl;
int main (void) {
int a, b;
cin >> a >> b;
if ((double)a > (double)b * 2 / 3) {
cout << "Yes" << "\n";
} else {
cout << "No" << "\n";
}
return 0;
}
Solution 2
Multiply the both sides of \(\displaystyle A > B \times \frac{2}{3}\) by \(3\) to obtain an equivalent inequality \(A \times 3 > B \times 2\). This allows to find the answer without relying on floating-point numbers but only on integers.
Sample code (Python):
a, b = map(int, input().split())
if (a*3 > b*2):
print("Yes")
else:
print("No")
Sample code (C++):
#include <iostream>
using std::cin;
using std::cout;
using std::cerr;
using std::endl;
int main (void) {
int a, b;
cin >> a >> b;
if (3 * a > 2 * b) {
cout << "Yes" << "\n";
} else {
cout << "No" << "\n";
}
return 0;
}
Bonus
Since \(A\) is an integer, \(\displaystyle A > B \times \frac{2}{3}\) is equivalent to \(\displaystyle A > \lfloor \frac{2B}{3} \rfloor\). Therefore, directly evaluating the expression in the problem using floor division also yields a correct answer.
- Find an example of \((A,B)\) such that \(\displaystyle A = B \times \frac{2}{3}\) is violated, but \(\displaystyle A = \lfloor \frac{2B}{3} \rfloor\) is satisfied.
- Find an example of \((A,B)\) such that \(\displaystyle A < B \times \frac{2}{3}\) is satisfied, but \(\displaystyle A < \lfloor \frac{2B}{3} \rfloor\) is violated.
- Do such examples exist even if the first and second inequalities are swapped?
posted:
last update: