Faizal and tower

5

3 votes
Easy-Medium
Problem

Faizal has N blocks. He wants to stack up these blocks to form a tower. Each block i has weight W[i] and capacity C[i]. A block can hold a stack of blocks whose total weight is within C[i]. This should include W[i], the weight of the current block, so assume that C[i]≥W[i] always.

Find the height of the tallest tower that Faizal can build.

Input :

First line contains N (N ≤ 5607)

Second line contains N spaced integers C1,C2,C3,...,Cn (C[i] ≤ 10^9)

Third line contains N spaced integers W1,W2,W3,...,Wn (W[i] ≤ 10^9)

C[i] >= W[i] ( 1 ≤ i ≤ N)

Output :

Print the height of the tallest tower that Faizal can build.

Time Limit: 2
Memory Limit: 256
Source Limit:
Editor Image

?