#C2921. Optimize Course Enrollments

    ID: 46291 Type: Default 1000ms 256MiB

Optimize Course Enrollments

Optimize Course Enrollments

You are given \(N\) students and \(M\) courses. Each student \(i\) has a maximum course enrollment capacity \(K_i\), and each course \(j\) has \(S_j\) available slots. A student may only enroll in a course if they are eligible for that course; the eligibility is provided in a matrix \(E\) where \(E_{i,j} = 1\) means student \(i\) is eligible for course \(j\), and 0 otherwise.

The goal is to assign students to courses by following these rules:

  • A student cannot be assigned to more than \(K_i\) courses.
  • A course cannot have more than \(S_j\) enrollments.
  • A student may enroll in a course only if they are eligible for it and have not already been enrolled in that course.

Your task is to compute and print an array of \(M\) integers where the \(j\)th integer indicates the total number of students enrolled in course \(j\).

inputFormat

The first line contains two integers (N) and (M) representing the number of students and courses respectively.\nThe second line contains (N) integers (K_1, K_2, \dots, K_N) where (K_i) is the maximum courses student (i) can enroll in.\nThe third line contains (M) integers (S_1, S_2, \dots, S_M) where (S_j) is the available slots in course (j).\nThis is followed by (N) lines, each with (M) integers. The (j)th number in the (i)th line is (E_{i,j}), indicating the eligibility of student (i) for course (j) (1 for eligible, 0 for not eligible).

outputFormat

Print (M) integers separated by a space. The (j)th integer is the total number of students enrolled in course (j).## sample

3 3
2 1 2
1 2 1
1 0 1
0 1 1
1 1 0
1 2 1

</p>