Official

A - Election 2 Editorial by en_translator


For beginners

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: