C - Standings Editorial by evima

Sample Implementation in Python

The specific implementation of the solution in the official editorial can vary quite a bit depending on the language, so I will provide a sample implementation in another language.

(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: