So, the orbit in which cells will be filled depends on the energy level and, accordingly, its energy. It can be calculated this way: n + Ln - is principal quantum noL is azimuthal quantum. Thus, the smaller the value n+L, the lower the energy of the sublevel and it will be filled first: for the s-orbitals the value is 0L, for the p-orbitals the value is 1L, for the d-orbitals the value is 2L.
Consider the transition of electrons from one sublevel to another in a cerium atom: on the 6s orbital, the energy value is 6, and on 5d sublevel the energy value is 7. Therefore, as mentioned earlier, first fill up with electrons of the 6s sublevel.