#3562
Maximum Profit from Trading Stocks with Discounts
expert · 1265 · lc hard +32 · 56.8% accepted · 375 likes · top 52%
Description
A company has n employees (employee 1 is CEO). Each employee i can buy a stock at price present[i] and sell it at future[i]. Hierarchy is given by hierarchy[i] = [ui, vi] (boss → subordinate).
If an employee's direct boss also buys stock, that employee pays floor(present[v] / 2) instead.
With a fixed budget, maximize profit (buy price subtracted from sell price) without exceeding it. Each stock can be bought at most once, and profit cannot fund more purchases.
Return the maximum achievable profit.
Code
1
2
3