#P2050. [NOI2012] 美食节
[NOI2012] 美食节
Description
To welcome students from all over the country, CZ City is hosting a grand food festival.
As a foodie who loves trying new things, Xiao M would not miss this feast. He quickly tasted all the foods at the festival. However, the desire to try new dishes is hard to satisfy. Although all dishes are delicious and the chefs cook fast, Xiao M still feels it is unbearable if there is no dish on his table that has already appeared on someone else’s table. So he begins to study the problem of cooking order, that is, arranging a cooking sequence so that the students’ waiting time is minimized.
Xiao M finds that there are different types of dishes. Each time they order, each student may choose exactly one dish. There are chefs to prepare these dishes. After all students finish ordering, the dish-making tasks are assigned to the chefs. Then all chefs start cooking simultaneously. The chefs follow the required sequence and can cook only one serving at a time.
In addition, Xiao M finds another interesting fact — although the chefs can all make all types of dishes, for the same dish, different chefs may take different amounts of time. He numbers the dishes and the chefs , and lets be the time for chef to make dish .
Xiao M defines the waiting time of each student as the duration from when all chefs start cooking until that student’s serving is completed. In other words, if a student’s dish is the -th dish made by some chef, then the student’s waiting time is the sum of the times of that chef’s first dishes. The total waiting time is the sum of all students’ waiting times.
Now Xiao M knows all the ordering information — there are students who ordered dish for . He wants to know the minimum possible total waiting time.
Input Format
The first line contains two positive integers and , the number of dish types and the number of chefs.
The second line contains positive integers; the -th number is , the number of students who ordered dish .
Then there are lines, each containing non-negative integers. In these lines, the -th number on the -th line is , the time needed for chef to make dish .
In the input file, adjacent numbers on each line are separated by a single space, and there are no extra spaces at the end of any line.
Output Format
Output a single line containing one integer: the minimum total waiting time.
3 2
3 1 1
5 7
3 6
8 9
47
Hint
Chef first makes serving of dish , then makes servings of dish . The waiting times of the students who ordered these servings are , , and .
Chef first makes serving of dish , then makes serving of dish . The waiting times of the students who ordered these servings are and .
The total waiting time is .
Although dishes and are faster if made by chef , the total waiting time would be longer if all these dishes were made by chef . If, as above, we reassign serving of dish and serving of dish to chef , then chef will not be idle, and the total waiting time is shorter.
It can be proved that there is no better ordering and assignment.
For each test set, the values of , , and are as follows:
- Test point : , , .
- Test point : , , .
- Test point : , , .
- Test point : , , .
- Test point : , , .
- Test point : , , .
- Test point : , , .
- Test point : , , .
- Test point : , , .
- Test point : , , .
Constraints for of the testdata: , , , (where ).
Translated by ChatGPT 5
京公网安备 11011102002149号