아직 만들고 있는 페이지입니다.

이 페이지는 아직 만드는 중입니다. 보이는 내용은 바뀔 수 있습니다.

Course Selection

시간 제한1초메모리 제한256 MB

요약
학생마다 원하는 5개 과목을 강의 정원 안에서 배정해 전체 수강 건수의 합이 최대가 되도록 만든다.
난이도

보통10점 중 7점

유형
그래프, 그리디, 완전 탐색
정답자
아직 제출이 없습니다

문제

The University of Wonderfulness has accidentally admitted more students than it has the capacity to teach. Unfortunately, this means that some of its courses may be full and some students might not be able to take the courses that they would like. Can you help the university manage the situation?

Each student has selected 5 courses that they would like to take. Each course has a hard limit on the number of students that can take it. Your task is to enroll each student into as many of their 5 selected courses as possible while respecting the course limits.

The happiness level of a student is the number of courses that they are enrolled in. If they can enroll in all 5 of their selected courses, their happiness level is 5. If two of their selected courses are full and they can enroll in only 3 of their 5 selected courses, their happiness level is only 3. The university wishes to maximize the sum of the happiness levels of all the students.

The objective can be phrased in a different but equivalent way. Each student pays \1000intuitionforeachcoursethattheyareenrolledin.Astudentwithall5oftheirselectedcoursespays1000 in tuition for each course that they are enrolled in. A student with all 5 of their selected courses pays \\5000. A student enrolled in only 3 of their 5 selected courses pays \$3000. The university wishes to maximize the total amount of tuition it can collect.

Your task is to assign students to courses while respecting the constraints and maximizing the total happiness level of the students and the total amount of tuition collected.

입력

The first line of input contains two integers separated by a space, 5≤c≤10005 ≤ c ≤ 1000, the number of courses, and 1≤s≤100001 ≤ s ≤ 10000, the number of students. It is followed by cc lines, the iith such line containing a single integer 1≤m_i≤100001 ≤ m\_i ≤ 10000, the maximum number of students that can be enrolled in the iith course. These cc lines are followed by ss more lines, one for each student. Each of these ss lines contains five distinct integers separated by spaces, the five courses that the student would like to take. Each of these course numbers is an integer 1≤i≤c1 ≤ i ≤ c, corresponding to the course whose limit m_im\_i was given on the iith of the cc lines following the first line of input.

출력

The first line of output should contain a single integer, the maximum sum of the happiness levels that can be achieved. This first line of output should be followed by ss more lines, one for each student, in the same order as in the input. Each of these lines should contain between 0 and 5 integers separated by spaces, the course numbers 1≤i≤c1 ≤ i ≤ c of the courses that the student is enrolled in to achieve the maximum sum of happiness levels on the first line of output.

If there are multiple assignments of courses to students that achieve the same maximum sum of happiness levels, you may output any one of those assignments and it will be considered correct.

예제1

  1. 예제 1

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