Optimal adaptation to extreme rainfalls in current and future climate