We consider a resource allocation problem, where a rational agent has to decide how to share a limited amount of resources among different companies that might be facing financial difficulties. The objective is to minimize the total long term cost incurred by the economy due to default events. Using the framework of multiarmed restless bandits and, assuming a two-state evolution of the default risk, the optimal dynamic resource sharing policy is determined. This policy assigns an index value to each company, which orders its priority to be funded. We obtain an analytical expression for this index, which generalizes the return-on-investment (ROI) index under the static setting, and we analyse the influence of the future events on the optimal dynamic policy. A discussion about the structure of the optimal dynamic policy is provided, as well as some extensions of the model.