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.

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:20
19 votes
Tags:
ApprovedDepth First SearchEasyGraphsReady
Points:30
20 votes
Tags:
Basic ProgrammingBasics of ImplementationImplementationMedium
Points:30
14 votes
Tags:
AlgorithmsApprovedMathMediumOpen