시간 제한메모리 제한제출정답맞힌 사람정답 비율
4 초 2048 MB2512861.538%

문제

End of semester is coming, and it is a hard time for students. There are $k$ courses and $n$ students, and every student should pick exactly one course and pass the exam on it.

If student $i$ picks exam $j$, the student's frustration will be $c_{i,j}$. The total frustration of students is the sum of their individual frustrations.

The teachers insist that, for each exam $j$, no more than $a_j$ students can pick this exam. What is the minimum possible total frustration the students may get?

입력

The first line contains two integers $n$ and $k$: the number of students and the number of exams ($1 \le n \le 50\,000$, $1 \le k \le 10$).

Then follow $n$ lines. In $i$-th of these lines, there are $k$ integers $c_{i,1}, c_{i,2}, \ldots, c_{i,k}$: the frustration of student $i$ if they choose the exam $1, 2, \ldots, k$ ($1 \le c_{i,j} \le 10^9$).

The last line contains $k$ integers $a_1, a_2, \ldots, a_k$: the maximum number of students that can pick exam $1, 2, \ldots, k$ ($0 \le a_j \le n$). It is guaranteed that $\sum a_j \ge n$.

출력

Print one integer: the minimum possible total frustration.

예제 입력 1

6 2
1 2
1 3
1 4
1 5
1 6
1 7
3 4

예제 출력 1

12

예제 입력 2

3 3
1 2 3
2 4 6
6 5 4
1 1 1

예제 출력 2

8