#P3545. Optimal Customer Demand Fulfillment
Optimal Customer Demand Fulfillment
Optimal Customer Demand Fulfillment
There are \(n\) days. On the \(i\)-th day, you acquire \(A_i\) items in the morning. At noon, a customer requests to purchase \(B_i\) items. You may choose to satisfy the customer's demand if, and only if, your available inventory is at least \(B_i\). When you satisfy a demand, your inventory decreases by \(B_i\); if you ignore the demand, your inventory remains unchanged. Note that the remaining inventory carries over to subsequent days. Your task is to determine the maximum number of days on which you can satisfy the customer demands by making optimal choices.
Note: You do not have to satisfy every customer's demand even if you have enough inventory. Sometimes, it might be more beneficial for future days to skip a demand, especially if the purchase request is large.
Mathematically, if you choose a subset of days \(S = \{i_1, i_2, \dots, i_k\}\) (with \(i_1 < i_2 < \cdots < i_k\)) to satisfy the demands, then for each \(1 \le j \le k\) the following must hold: \[ \sum_{r=1}^{i_j}A_r - \sum_{r=1}^{j-1}B_{i_r} \ge B_{i_j}. \]
inputFormat
The first line contains an integer \(n\) representing the number of days.
The second line contains \(n\) space-separated integers \(A_1, A_2, \dots, A_n\), where \(A_i\) is the number of items acquired on day \(i\).
The third line contains \(n\) space-separated integers \(B_1, B_2, \dots, B_n\), where \(B_i\) is the number of items the customer requests on day \(i\).
outputFormat
Output a single integer: the maximum number of days on which you can satisfy the customer demands.
sample
3
10 10 10
5 15 5
3