Optimizing Cybersecurity Investments over Time