Popeala
Time limit2sMemory limit512 MB
Partition T weighted test cases into exactly K consecutive subtasks to minimize total scored points, for each K up to S.
- Level
Hard8 of 10
- Topics
- Dynamic programming, Prefix sum, Divide and conquer
- Solved
- No attempts yet
Problem
The Romanian word popeală comes from the historical novella "Alexandru Lăpușneanul". The word came back into use in the Romanian programming contest scene, where it describes any situation in which the scientific committee makes life harder for the contestants in an unorthodox and usually involuntary way: very strict time limits, invalid test data, wrong statements, stolen keyboards. This task is about one of those situations.
A contest has contestants. It has a single task, and that task has test cases. The committee wants to group these test cases into subtasks.
Subtasks work like this. Each test case belongs to exactly one subtask. A subtask may contain any number of test cases, but it cannot be empty. If a contestant fails any test case of a subtask, that contestant scores on that subtask. Otherwise the contestant scores the sum of the point values of all test cases in that subtask.
The committee does the grouping after the contest is over. It already knows which test cases each contestant solved, so it will group the test cases so that the total number of points scored in the contest is as small as possible.
You are given an array of size , where is the point value of the -th test case. You are also given a matrix of size , where is if the -th contestant solved the -th test case correctly and otherwise. The committee has already decided that every subtask holds consecutive test cases. In other words, if test cases and end up in the same subtask, then every test case with belongs to that subtask too.
For each with , find the minimum total number of points that can be scored in the contest when the test cases are grouped into exactly subtasks.
Input
The first line contains three space-separated integers , , .
The second line contains space-separated integers. The -th of them is .
Each of the next lines contains a string of length made of the characters and . The -th character of the -th such line is .
- ()
Output
Print lines. The -th line contains one integer: the minimum total number of points that can be scored in the contest when the test cases are grouped into exactly subtasks.
Hint
In the first example there are contestants, test cases and , so the minimum has to be computed for , and subtasks. The point values are , , .
With a single subtask all three test cases fall into it. Neither contestant solved every test case, so the total is .
With two subtasks there are two ways to group the test cases. One gives a total of points and the other gives , so the smaller one, , is chosen.
With three subtasks there is only one grouping, and it gives a total of points.