C - Standings Editorial by evima

他言語での実装例

公式解説 の解法の具体的な実装は言語によって比較的大きく変わりうるため、 他言語での実装例を掲載しておきます。

(Python, https://atcoder.jp/contests/abc308/submissions/43071823)

class Frac:
    def __init__(self, a, b):
        self.a, self.b = a, b
    
    def __lt__(self, other):
        return self.a * other.b < self.b * other.a

N = int(input())
A, B = [0], [0]
for i in range(N):
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)
l = sorted(range(1, N + 1), key=lambda i: Frac(-A[i], A[i] + B[i]))
print(' '.join(map(str, l)))

posted:
last update: