Gummy Candies
Time limit3sMemory limit1024 MB
Pick candies so every color appears equally often, and find the minimum cost for each total weight remainder modulo m.
- Level
Medium7 of 10
- Topics
- Dynamic programming, Shortest path
- Solved
- No attempts yet
Problem
Bajtek loves gummy candies. A newly opened shop sells only gummy candies, and it offers n kinds. The i-th kind is described by its color k_i, its weight m_i in bytegrams, and its price c_i in bytegroshes. Candies are sold one at a time, and the shop has an unlimited supply of each kind. Colors are numbered from 1 to k.
Bajtek buys a multiset of candies only if every color from 1 to k appears exactly the same number of times in it. For each integer r in , find the minimum total price Bajtek must pay for a multiset whose total weight leaves remainder r when divided by m.
Input
The first line contains three integers n, k, and m (). Each of the next n lines contains three integers k_i, m_i, and c_i (, , ).
Output
Print m lines. The i-th line contains the minimum total price of a valid multiset whose total weight leaves remainder i-1 when divided by m. If no such multiset exists, print -1 instead.