Company: Publicis_Sapient_9_jan
Difficulty: medium
Portfolio Backtesting Problem Description You want to maximize the profit from a trading portfolio while taking a minimum number of losses. Given: An array pnl of n integers representing monthly profits/losses (negative values are losses). An integer k representing the minimum number of losses that must be taken. The traders can: Add any positive pnl[i] to their profit. For negative pnl[i] , either subtract its magnitude or skip it. The net profit must always be non-negative. Find the maximum total profit that can be earned after taking at least k losses. Return -1 if it is not possible to achieve a non-negative profit under these conditions. Function Description Complete the function getMaxProfit . It has the following parameters: vector<int> pnl : A vector of integers representing the profit/loss predicted. int k : An integer representing the minimum number of losses that must be taken. Returns long : The maximum profit after taking at least k losses, or -1 if not possible. Exa