A - Election 2 Editorial by en_translator
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.
First, let us consider when Takahashi’s or Aoki’s victory is already decided. If either candidate already have \(\lceil \frac{N}{2} \rceil\) or more votes, then the other never wins even if he gets the remaining. Conversely, if both candidates do not have \(\lceil \frac{N}{2} \rceil\) votes yet, then both may win, so the winner is not confirmed yet.
Implement this condition in an if
statement.
Determine if \(T \geq \lceil \frac{N}{2} \rceil\) or \(A \geq \lceil \frac{N}{2} \rceil \). In most programming languages, N / 2
is a floor division. If you actually want to find \( \lceil \frac{N}{2} \rceil \), evaluate (N + 1) / 2
.
Sample code (C++):
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, t, a;
cin >> n >> t >> a;
if (a >= (n + 1) / 2 || t >= (n + 1) / 2) {
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
}
Sample code (Python):
n, t, a = map(int, input().split())
if a >= (n+1)//2 or t >= (n+1)//2:
print("Yes")
else:
print("No")
posted:
last update: