Optimal charge inhomogeneity for the d+id-wave superconductivity in the intercalated graphite CaC6