eolymp
bolt
Try our new interface for solving problems
Problems

The Merry Student Life During the Term...

The Merry Student Life During the Term...

As Vasya Pupkin has completed no labs since the start of the term, the dean has threatened to expel him. Vasya would really like to avoid that, so, finally, he decided to get serious... During this term, Vasya is enrolled in \textbf{N} classes, and each of them asks for \textbf{K_i} labs (\textbf{1} ≤ \textbf{i} ≤ \textbf{N}). Vasya realizes it's impossible to study all subjects at once, so he has decided to study one of them, then do all the labs in that subject, and only then turn to the next subject... \includegraphics{https://static.e-olymp.com/content/93/93fac9bf80c119dd3dc15cac80ae6a465c389659.jpg} The labs in one subject can be done in any order, but the lab instructors will assign penalties for lab work that is turned in late. The penalty depends on the time when the work was actually turned in and equals \textbf{w_j}·\textbf{t_j} for every \textbf{1} ≤ \textbf{j} ≤ \textbf{T}, where \textbf{w_j} is a coefficient given by the lab instructor, \textbf{t_j} is the time when the work for the lab \textbf{j} is turned in, and \textbf{T} = \textbf{K_i} is the total number of labs to be done. The time needed to perform the lab (after studying the subject, of course) is known for each lab and equals \textbf{p_j} for every \textbf{1} ≤ \textbf{j} ≤ \textbf{T}. Help Vasya find the order of tackling the subjects that minimizes the total penalty \includegraphics{https://static.e-olymp.com/content/ab/ab0073311beb50e104aed3a8a613e284afef34eb.jpg} w_j·t_j. Assume that all labs are done immediately one after another and that the times to study the subjects are negligible compared to the lab times. \InputFile The first input line contains the integer \textbf{N} (\textbf{1} ≤ \textbf{N} ≤ \textbf{500}). The second line contains the \textbf{N} values of \textbf{K_i} (\textbf{1} ≤ \textbf{K_i} ≤ \textbf{100}). The third line contains \textbf{T} integers, the values of \textbf{p_j} (\textbf{1} ≤ \textbf{j} ≤ \textbf{T}), where the labs for the first subject are listed first, then the labs for the second subject, and so on. Finally, the fourth line contains the values of \textbf{w_j} in the same order. All the values \textbf{p_\{j \}}and \textbf{w_j} are positive integers not exceeding \textbf{10000}. \OutputFile The first output line should contain the minimal total penalty (an integer). The second line should contain a permutation of the integers \textbf{1}...\textbf{T} that achieves the minimal penalty. If there are several possible solutions, output any one of them.
Time limit 2 seconds
Memory limit 256 MiB
Input example #1
1
5
1 2 3 4 5
5 4 3 2 1
Output example #1
70
1 2 3 4 5
Source NEERC Western Subregional Contest 2012