Poor Students

시간 제한4초메모리 제한2048 MB

요약
n명의 학생을 k개 시험에 배정하되 각 시험의 정원 a_j를 지키면서 전체 불만족도의 합을 최소로 만든다.
난이도

보통10점 중 6점

유형
최소 신장 트리, 그리디, 그래프, 정렬
정답자
아직 제출이 없습니다

문제

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

If student ii picks exam jj, the student's frustration will be c_i,jc\_{i,j}. The total frustration of students is the sum of their individual frustrations.

The teachers insist that, for each exam jj, no more than a_ja\_j students can pick this exam. What is the minimum possible total frustration the students may get?

입력

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

Then follow nn lines. In ii-th of these lines, there are kk integers c_i,1,c_i,2,…,c_i,kc\_{i,1}, c\_{i,2}, \ldots, c\_{i,k}: the frustration of student ii if they choose the exam 1,2,…,k1, 2, \ldots, k (1≤c_i,j≤1091 \le c\_{i,j} \le 10^9).

The last line contains kk integers a_1,a_2,…,a_ka\_1, a\_2, \ldots, a\_k: the maximum number of students that can pick exam 1,2,…,k1, 2, \ldots, k (0≤a_j≤n0 \le a\_j \le n). It is guaranteed that ∑a_j≥n\sum a\_j \ge n.

출력

Print one integer: the minimum possible total frustration.

예제2

  1. 예제 1

    입력
    6 2
    1 2
    1 3
    1 4
    1 5
    1 6
    1 7
    3 4
    
    예상 출력
    12
    
  2. 예제 2

    입력
    3 3
    1 2 3
    2 4 6
    6 5 4
    1 1 1
    
    예상 출력
    8