Advertisement
jbn6972

Enjoy the match

Dec 5th, 2021
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.50 KB | None | 0 0
  1. for _ in range(int(input())):
  2. n = int(input())
  3. matches = []
  4. for h in range(n):
  5. s, r = map(int, input().split())
  6. matches.append([r, s])
  7. matches.sort()
  8. enjoyment = 0
  9. x = 1
  10. tot = 0
  11. watch_list = {}
  12. for match in matches:
  13. if match[1] not in watch_list:
  14. watch_list[match[1]] = 1
  15. enjoyment += match[0]*x
  16. x += 1
  17. else:
  18. tot += match[0]
  19. enjoyment += tot * (x - 1)
  20. print(enjoyment)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement