Promotion
Practice
4 (14 votes)
Ad Hoc
Approved
Binary search
Data structures
Medium
Open
Sorting
Problem
82% Success 2541 Attempts 30 Points 1s Time Limit 256MB Memory 1024 KB Max Code

Ramesh is a hard-working employee.Seeing his dedication towards his work his boss decided to promote him. Ramesh was overjoyed on getting to know this.But soon he realized he needed to shift to another Town X. Ramesh needed to transport his n boxes to Town X for which he contacted the company "Packers and Movers".This company sent him m trucks.Each truck took 1 hour to go from his house to Town X and another 1 hour to return.But each truck could carry only 1 box at a time and also each truck has a limit for the maximum weight of the box it can carry.A truck can be used multiple times. Since Ramesh is busy he gives you the job for finding the minimum time in which he can transfer all his n boxes to Town X.

INPUT
The first line contains 2 integers n and m.The next line contains n integers denoting the weight of each box.This is followed by a line containing m integers denoting the maximum capacity of each truck.

Output
Print the minimum time to transfer all the boxes to Town X.

Constraints
1<=n,m<=10000
1<=weight of each box<=1000000
1<=maximum capacity of each truck<=1000000

Note: A solution always exist.

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:50
13 votes
Tags:
Medium-Hard
Points:30
8 votes
Tags:
AlgorithmsBinary SearchHiringImplementationMediumSearchingString Manipulation
Points:30
24 votes
Tags:
AlgorithmsApprovedData StructuresMediumOpenSorting