Fill the boxes
Practice
3.4 (9 votes)
Basic programming
Basics of implementation
Implementation
Medium
Sorting
Two pointer
Problem
48% Success 6316 Attempts 30 Points 1s Time Limit 256MB Memory 1024 KB Max Code
You are given an array of size N, denoting capacity of N boxes, and an integer K, denoting extended capacity factor. You are also given the weights of M balls. Each \(i^{th}\) box can accommodate exactly one ball having weight in range \([capacity_i, capacity_i+K]\) (both inclusive). Find the maximum number of boxes that can be filled.
Constraints:
- \(1 ≤ T ≤ 50\)
- \(1 ≤ N,M ≤ 10000\)
- \(1 ≤ K ≤ 1000\)
- \(1 ≤ Capacity_i ≤ 1000\)
- \(1 ≤ Weight_i ≤ 2000\)
Input format:
First line: T i.e. Number of test cases.
For each test case:
First line: Three space-separated integers N, M and K.
Second line: N space-separated integers denoting the capacity of boxes.
Third line: M space-separated integers denoting the weight of balls.
Output format:
For each test case, print the answer in a separate line.
Submissions
Please login to view your submissions
Similar Problems
Points:30
9 votes
Tags:
Mediumad hocapproved
Points:30
14 votes
Tags:
AlgorithmsApprovedMathMediumOpen
Points:30
207 votes
Tags:
ApprovedMathMediumReady
Editorial