Popeala

Partition T weighted test cases into exactly K consecutive subtasks to minimize total scored points, for each K up to S.

Hard8Dynamic programmingPrefix sumDivide and conquerNo attempts yetTime limit2sMemory limit512 MB

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 NN contestants. It has a single task, and that task has TT 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 00 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 Points\mathrm{Points} of size TT, where Points[i]\mathrm{Points}[i] is the point value of the ii-th test case. You are also given a matrix Results\mathrm{Results} of size N×TN \times T, where Results[i][j]\mathrm{Results}[i][j] is 11 if the ii-th contestant solved the jj-th test case correctly and 00 otherwise. The committee has already decided that every subtask holds consecutive test cases. In other words, if test cases XX and YY end up in the same subtask, then every test case ZZ with XZYX \le Z \le Y belongs to that subtask too.

For each KK with 1KS1 \le K \le S, find the minimum total number of points that can be scored in the contest when the test cases are grouped into exactly KK subtasks.

Input

The first line contains three space-separated integers NN, TT, SS.

The second line contains TT space-separated integers. The ii-th of them is Points[i]\mathrm{Points}[i].

Each of the next NN lines contains a string of length TT made of the characters 00 and 11. The jj-th character of the ii-th such line is Results[i][j]\mathrm{Results}[i][j].

  • 1T200001 \le T \le 20000
  • 1N501 \le N \le 50
  • 1Smin(50,T)1 \le S \le \min(50, T)
  • 1Points[i]100001 \le \mathrm{Points}[i] \le 10000 (1iT1 \le i \le T)
  • (Points[1]+Points[2]++Points[T])×N2×109(\mathrm{Points}[1] + \mathrm{Points}[2] + \dots + \mathrm{Points}[T]) \times N \le 2 \times 10^9

Output

Print SS lines. The ii-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 ii subtasks.

Hint

In the first example there are 22 contestants, 33 test cases and S=3S = 3, so the minimum has to be computed for 11, 22 and 33 subtasks. The point values are 44, 33, 55.

With a single subtask all three test cases fall into it. Neither contestant solved every test case, so the total is 00.

With two subtasks there are two ways to group the test cases. One gives a total of 1212 points and the other gives 88, so the smaller one, 88, is chosen.

With three subtasks there is only one grouping, and it gives a total of 1616 points.