Problem 4: Financial Planning

https://open.kattis.com/problems/financialplanning

Given an integer dd representing the number of days elapsed, we can determine the total profit following the optimal investment strategy. This involves only choosing investments that bring in a net profit after d d days. We can do this by thinking of each investment option as a linear function of the form P(d)=pidciP(d) = p_id - c_i, where P(d) P(d) is the net profit (or loss).

We want to find the earliest day d d so that the profit following the optimal investment strategy is at least M M.

  • If dd is not a day where the profit following the optimal investment strategy is at least M M, then all days before dd do not have profits reachingM M.

  • However, if dd is a day where the profit following the optimal investment strategy is at least M M, then all days after dd can't be the earliest day with profits of at least M M.

Therefore, we can find the earliest day d dusing binary search.

This solution requires arithmetic with potentially very large numbers, so use long long (or even __int128) whenever possible.

Last updated