War of Kingdoms

Limits: 2s, 1.0 GB

There is a country named WARLAND. It is a big country, so it is divided into N kingdoms. Each kingdom has a King and an army of Wi warlords & Si soldiers. Each king also possesses Mi amount of wealth. Obviously it’s not possible that all the armies in the country are of equal strength. In a army each warlords and soldiers has their own power, and an army’s strength is measured using this formula: where: Pwi is the power of i-th warlord, Psj is the power of j-th soldier & M is the amount of wealth for a particular kingdom.

This is a companion discussion topic for the original entry at https://toph.co/p/war-of-kingdoms

@hjr265 formula is missing