How do I compare the amount of item all the players have and switch the person who has the most items to a different team?

How do I compare the amount of item all the players have and switch the person who has the most items to a diffrent team?

To switch teams use a team switcher but you could have all items stored in a property and compare them using blocks