Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- for _ in range(int(input())):
- n = int(input())
- matches = []
- for h in range(n):
- s, r = map(int, input().split())
- matches.append([r, s])
- matches.sort()
- enjoyment = 0
- x = 1
- tot = 0
- watch_list = {}
- for match in matches:
- if match[1] not in watch_list:
- watch_list[match[1]] = 1
- enjoyment += match[0]*x
- x += 1
- else:
- tot += match[0]
- enjoyment += tot * (x - 1)
- print(enjoyment)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement