Created
February 14, 2021 05:30
This is my code of Problem D of AtCoder Beginner Contest 187.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 入力 | |
N = int(input()) | |
yuukensha = [[int(x) for x in input().split()] for _ in range(N)] | |
# X=高橋票-青木票の数を考える | |
# 初期Xは-1*(全青木派有権者) | |
X = 0 | |
for i in range(N): | |
X -= yuukensha[i][0] | |
# i番目の町で演説をすると、Xは2A_i+B_i増える | |
# 演説する数をなるべく減らしたいので、 | |
# 2A_i+B_iのリストをつくりソートする | |
enzetsu_kouka = sorted([2*yuukensha[i][0] + yuukensha[i][1] for i in range(N)], reverse=True) | |
# 答えを格納する変数 | |
ans = 0 | |
# Xに2A_i+B_iを大きい順に足していく | |
# X>0になったら終了 | |
for i in range(N): | |
X += enzetsu_kouka[i] | |
ans += 1 | |
if X > 0: | |
print(ans) | |
exit() | |
# 全ての町で演説したら必ず勝つのでここに来ることはないけど一応 | |
print("error") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment