Stacking boxes - MarisaOJ: Marisa Online Judge

Stacking boxes

Time limit: 1000 ms
Memory limit: 256 MB
You are given n boxes, each with a weight denoted by W1,W2,…,Wn. These boxes can be stacked on top of each other, and each box i has a weight capacity denoted by Ci, indicating the maximum weight it can withstand when other boxes are placed on top of it. Your task is to determine the maximum number of boxes that can be stacked together while ensuring that the weight capacity of each box is not exceeded. ### Input - The first line contains an integer n. - The second line contains n integer Wi. - The third line contains n integer Ci. ### Output - Print an integer, the maximum number of boxes can be stacked. ### Constraints - 1≤n≤5000. - 1≤Wi≤1010. - 1≤Ci≤1010. ### Example Input: 31120301110010 Output: 2