Devil's Hell deLivery

시간 제한2초메모리 제한1024 MB

요약
무게가 있는 아이템 최대 9개를 최대 5대의 트럭에 용량을 넘지 않게 담아, 필요한 최소 라운드 수를 구하고 배정까지 출력한다.
난이도

어려움10점 중 8점

유형
백트래킹, 비트 연산, 그리디, 이분 탐색
정답자
아직 제출이 없습니다

문제

Devil's Hell deLivery company delivers literally everything: boxes, packages, packets, datagrams et cetera.

The delivery process from city A to city B works as follows. There are NN trucks and KK items. The capacity of truck number ii equals c_ic\_i. The weight of item number jj equals w_jw\_j. The trucks make one or more delivery steps.

During one step, some items are loaded into some trucks. Items can not be split. Each truck's capacity must not be exceeded by the total weight of the items assigned to it. All trucks depart simultaneously.

At the end of each step, all trucks come back to the place where they started. If there are any items left, another step is performed.

Your task is to distribute items among steps and trucks so that the number of steps is minimized.

입력

The input contains up to a hundred test cases.

Each test case starts with a single line containing two integers NN and KK (1≤N≤51 \le N \le 5, 1≤K≤91 \le K \le 9): the number of trucks and the number of items, respectively. The following line consists of NN integers c_1,…,c_Nc\_1, \ldots, c\_N (1≤c_i≤1081 \le c\_i \le 10^8): the capacities of the trucks. The following line consists of KK integers w_1,…,w_Kw\_1, \ldots, w\_K (1≤w_i≤1081 \le w\_i \le 10^8): the weights of the items.

출력

For each test case, if the delivery is impossible, write a single line with a single integer −1-1.

Otherwise, start with a line containing a single integer SS: the number of steps required. This number must be minimized. After that, write SS lines describing the steps. Each step description must start with an integer I_iI\_i, the number of items delivered during the step. This number must be followed by I_iI\_i pairs a_ja\_j b_jb\_j. Each pair a_ja\_j b_jb\_j means that the item a_ja\_j is assigned to the truck b_jb\_j.

If there is more than one possible optimal answer, write any one of them.

예제1

  1. 예제 1

    입력
    2 4
    10 20
    5 5 5 5
    2 1
    10 10
    20
    
    예상 출력
    1
    4 1 1 2 1 3 2 4 2
    -1