Flat bands pinned to the Fermi surface and the phase diagram of electron-doped high-Tc superconductors