[AtCoder] ABC308C Standings

유제훈·2023년 7월 21일

AtCoder

목록 보기
1/1
post-thumbnail

실수를 비교해야 하는 문제이다.
비교를 정확하게 하기 위해 분자와 분모를 곱해주는 방식으로 변형해서 푼다.!

class Rate:

    def __init__(self, x, y) -> None:
        self.x = x
        self.y = y
    
    def __lt__(self, other):
        return self.x * other.y < self.y * other.x


N = int(input())
A = [0]
B = [0]
for _ in range(N):
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)

sort = sorted(range(1, N + 1), key=lambda i: Rate(-A[i], A[i] + B[i]))
print(' '.join(map(str, sort)))
profile
🌱 새싹 개발자

0개의 댓글