Question bank › Greedy
Dsa Greedy Easy

The Busy Blacksmith

A blacksmith has N custom tool orders. Each order i takes T[i] hours to complete. Each customer has a 'patience penalty' P[i], which is the amount of money the blacksmith loses for every hour that passes until THAT specific order is completed. The blacksmith can only work on one order at a time and cannot pause an order once started. Find the minimum total penalty the blacksmith will incur across all orders. Input Format: The first line contains an integer N. The next N lines each contain two integers: T[i] (duration) and P[i] (penalty rate). Output Format: A single integer representing the minimum total penalty. Example: Input: 2 3 10 1 5 Output: 45 Explanation: If order 1 is done first (3 hours), penalty is (3*10) + (4*5) = 50. If order 2 is done first (1 hour), penalty is (1*5) + (4*10) = 45. Min is 45.

Key concepts

greedysortingscheduling

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
Part of InterviewLab's verified interview question bank. We show the prompt and concepts to practise with — never a copy-paste solution.