Optical gain of a quantum-well laser with non-Markovian relaxation and many-body effects