An Analytical Theory for the Growth from Planetesimals to Planets by Polydisperse Pebble Accretion