How do the airlines allot the passengers seats to make sure the balance is maintained?
It depends on the specific limitations of the aircraft and the flight booking load. If the flight is full, it not really an issue. Typically the check-in system will automatically distribute passengers throughout the cabin, starting from the front and moving backwards. Load planners may block rows during check-in if the flight is so empty the center of gravity will be exceeded, unless passengers sit in certain sections of the aircraft.