Under construction

Still being built. Things may change

Problem Made Because Delivery Fees Were Too High

Time limit3sMemory limit1024 MB

Summary
Assign N students to M restaurants so each student's equal share of the fee stays within their limit, minimizing the total fee.
Level

Medium6 of 10

Topics
Dynamic programming, Bit manipulation
Solved
No attempts yet

Problem

Students at Korea Science Academy often order food for delivery on weekends. Delivery fees have risen sharply, so more students order together.

Each of NN students chooses exactly one of MM restaurants and places an order there. Students who pick the same restaurant can share the order and split its delivery fee equally. If the jj-th restaurant is ordered from, a delivery fee of cjc_j is charged, and the students who ordered from that restaurant split this fee equally. The fee each student pays does not have to be an integer. The ii-th student can order from the jj-th restaurant only if the fee that student would pay there is at most ri,jr_{i,j}.

Doyoung wants to decide which restaurant each student orders from so that the total delivery fees paid by all students is minimized. Find the minimum possible total.

Input

The first line contains two integers NN and MM, separated by a space.

The second line contains MM integers c1,c2,⋯ ,cMc_1, c_2, \cdots, c_M, separated by spaces.

The next NN lines contain ri,jr_{i,j}. The ii-th of these lines contains MM integers ri,1,ri,2,⋯ ,ri,Mr_{i,1}, r_{i,2}, \cdots, r_{i,M}, separated by spaces.

Output

Print the minimum possible total of delivery fees. If it is impossible for every student to place an order, print -1 instead.

Constraints

  • 1≤N≤151 \leq N \leq 15
  • 1≤M≤10001 \leq M \leq 1000
  • 1≤cj≤1071 \leq c_j \leq 10^7
  • 0≤ri,j≤1070 \leq r_{i,j} \leq 10^7

Examples3

  1. Example 1

    Input
    3 3
    3 2 10
    2 0 4
    2 0 4
    0 2 4
    
    Expected output
    5
    
  2. Example 2

    Input
    3 3
    3 2 10
    2 0 4
    1 0 4
    0 2 4
    
    Expected output
    10
    
  3. Example 3

    Input
    4 2
    8 8
    3 2
    3 2
    3 1
    0 2
    
    Expected output
    -1