Dsa
Greedy
Medium
Delivery Route Optimization
You are in charge of optimizing delivery routes for a logistics company. Each delivery has a specific distance and a priority. Your goal is to schedule deliveries to maximize priority while minimizing the total distance traveled. Write a program that receives a list of deliveries and calculates the maximum priority that can be achieved based on the total distance restrictions.
Input format:
- The first line contains two integers D (1 ≤ D ≤ 1000) and M (1 ≤ M ≤ 5000), representing the number of deliveries and maximum total distance.
- The next D lines contain two integers Di (1 ≤ Di ≤ 1000) and Pi (1 ≤ Pi ≤ 100), representing the distance and priority of each delivery.
Output format:
- A single integer representing the maximum priority achievable under the distance constraint.
Example:
Input:
4 10
2 10
3 30
5 20
1 5
Output:
35
Key concepts
greedyroute planninglogistics
Practise this out loud — free
Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.
🎙 Practise this question now