Problem Made Because Delivery Fees Were Too High
Time limit3sMemory limit1024 MB
Assign N students to M restaurants so each student's equal share of the fee stays within their limit, minimizing the total fee.
- Level
Medium6 of 10
- Topics
- Dynamic programming, Bit manipulation
- Solved
- No attempts yet
Problem
Students at Korea Science Academy often order food for delivery on weekends. Delivery fees have risen sharply, so more students order together.
Each of students chooses exactly one of restaurants and places an order there. Students who pick the same restaurant can share the order and split its delivery fee equally. If the -th restaurant is ordered from, a delivery fee of is charged, and the students who ordered from that restaurant split this fee equally. The fee each student pays does not have to be an integer. The -th student can order from the -th restaurant only if the fee that student would pay there is at most .
Doyoung wants to decide which restaurant each student orders from so that the total delivery fees paid by all students is minimized. Find the minimum possible total.
Input
The first line contains two integers and , separated by a space.
The second line contains integers , separated by spaces.
The next lines contain . The -th of these lines contains integers , separated by spaces.
Output
Print the minimum possible total of delivery fees. If it is impossible for every student to place an order, print -1 instead.