AmazonOA #276
Maximum Number of Days to Survive
困难可在线判题
考点(AI 标注)贪心调度
Each day you borrow from a lender you have not used before. Lender i lends lender[i], which must be repaid as payback[i] the next day. On the first day you may pick any lender; on every later day, the new loan must be enough to repay the previous one, and any leftover cash is spent that day and does not carry over. Find the maximum number of consecutive days of successful borrowing. The last day counts as soon as its loan is obtained; there does not need to be a later loan to repay this last one. Each lender can be used at most once.
The bounds on n and the amounts below are an exact-solution range explicitly added by this site; they are not claimed to be the source's original bounds, and no assumption payback≥lender is added. On day two of original example 3 you should borrow 2 and repay 2, then owe 3; the original text "borrow 1, repay 2" is wrong.
输入格式
The first line contains n, the second line contains n lender values, and the third line contains n payback values. Added by this site: 1≤n≤20, 1≤lender[i],payback[i]≤10^9, and both arrays have the same length. payback may be less than, equal to, or greater than the corresponding lender.
输出格式
Output the maximum number of days of successful borrowing, an integer in 1..n.
样例 1
输入:
4
4 6 1 8
7 10 3 9
输出:
3
样例 2
输入:
3
2 1 5
2 2 5
输出:
3
样例 3
输入:
3
100 1 2
1 100 2
输出:
3
样例说明
In example 1, borrowing loans of 1→4→8 lasts 3 days. In example 2, borrowing loans of 1→2→5 lasts 3 days; repaying exactly is also valid. In example 3, borrowing by indices 2→1→3 (numbered from 1) lasts 3 days, while greedily picking lender 1, who has the smallest payback, on the first day lasts only 2 days.