An improper estimator with optimal excess risk in misspecified density estimation and logistic regression