This paper considers an optimal investment and reinsurance problem for an insurance company, where the surplus follows a linear diffusion. Contrary to classical models the insurer can continue doing business even if the surplus becomes negative, but penalty payments occur depending on the level of the current surplus. The insurer can invest in n risky assets and reduce the insurance risk either by excess of loss or by proportional reinsurance. The aim is to find an optimal investment and reinsurance strategy which minimises the penalty payments. We consider various penalty functions and derive closed form solutions.