Question bank › Greedy
Dsa Greedy Medium

Optimal Candy Distribution

A chocolate factory is producing various types of candies, and you need to distribute them to children such that each child gets at least one candy. Each type of candy has a different amount of candies available and a different sweetness level. You want to maximize the total sweetness across all distributed candies, while ensuring that the number of candies you distribute is equal to the number of children. Write a program that computes the maximum total sweetness you can achieve. Input format: - The first line contains two integers C (1 ≤ C ≤ 1000) and K (1 ≤ K ≤ 1000), the number of types of candies and the number of children respectively. - The next C lines contain two integers A (1 ≤ A ≤ 1000) and S (1 ≤ S ≤ 100) representing the amount of candies available and the sweetness level. Output format: - A single integer representing the maximum total sweetness achievable. Example: Input: 3 5 10 5 8 10 4 8 Output: 40

Key concepts

greedydistributionoptimization

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