E - Product Development Editorial /

Time Limit: 4 sec / Memory Limit: 1024 MB

配点 : 475475

問題文

AtCoder 社はある商品の開発をしようとしています。この商品には KK 個のパラメーターがあり、現段階ではすべてのパラメーターの値が 00 です。AtCoder 社の目標は、パラメーターの値を全て PP 以上にすることです。

ここで、NN 個の開発案があります。i(1iN)i(1 \le i \le N) 個目の開発案を実行すると、1jK1 \le j \le K を満たす整数 jj 全てに対して jj 個目のパラメーターが Ai,jA_{i,j} 上がりますが、この開発案を実行するにはコストが CiC_i かかります。

同じ開発案を 22 回以上実行することは出来ません。AtCoder 社が目標を達成出来るか判定し、出来る場合は目標を達成するのに必要なコストの総和の最小値を求めてください。

制約

  • 1N1001 \le N \le 100
  • 1K,P51 \le K,P \le 5
  • 0Ai,jP(1iN,1jK)0 \le A_{i,j} \le P(1 \le i \le N,1 \le j \le K)
  • 1Ci109(1iN)1 \le C_i \le 10^9(1 \le i \le N)
  • 入力は全て整数

入力

入力は以下の形式で標準入力から与えられる。

NN KK PP
C1C_1 A1,1A_{1,1} A1,2A_{1,2} \dots A1,KA_{1,K}
C2C_2 A2,1A_{2,1} A2,2A_{2,2} \dots A2,KA_{2,K}
\dots
CNC_N AN,1A_{N,1} AN,2A_{N,2} \dots AN,KA_{N,K}

出力

AtCoder 社が目標を達成出来るならば目標を達成するのに必要なコストの総和の最小値を、出来ないならば -1 を出力せよ。


入力例 1Copy

Copy
4 3 5
5 3 0 2
3 1 2 3
3 2 4 0
1 0 1 4

出力例 1Copy

Copy
9

11 個目と 33 個目と 44 個目の開発案を実行すると、それぞれのパラメーターが 3+2+0=5,0+4+1=5,2+0+4=63+2+0=5,0+4+1=5,2+0+4=6 で全て 55 以上となるため目標を達成できます。この場合コストの総和は 5+3+1=95 + 3 + 1 = 9 となります。

コストの総和 88 以下で目標を達成することは出来ません。よって答えは 99 です。


入力例 2Copy

Copy
7 3 5
85 1 0 1
37 1 1 0
38 2 0 0
45 0 2 2
67 1 1 0
12 2 2 0
94 2 2 1

出力例 2Copy

Copy
-1

どのようにしても目標を達成することは出来ません。よって -1 を出力します。

Score : 475475 points

Problem Statement

AtCoder Inc. is planning to develop a product. The product has KK parameters, whose values are currently all zero. The company aims to raise all parameter values to at least PP.

There are NN development plans. Executing the ii-th development plan (1iN1 \le i \le N) increases the value of the jj-th parameter by Ai,jA_{i,j} for every integer jj such that 1jK1 \le j \le K, at the cost of CiC_i.

A development plan cannot be executed more than once. Determine whether the company can achieve its goal, and if it can, find the minimum total cost required to achieve the goal.

Constraints

  • 1N1001 \le N \le 100
  • 1K,P51 \le K,P \le 5
  • 0Ai,jP(1iN,1jK)0 \le A_{i,j} \le P(1 \le i \le N,1 \le j \le K)
  • 1Ci109(1iN)1 \le C_i \le 10^9(1 \le i \le N)
  • All input values are integers.

Input

The input is given from Standard Input in the following format:

NN KK PP
C1C_1 A1,1A_{1,1} A1,2A_{1,2} \dots A1,KA_{1,K}
C2C_2 A2,1A_{2,1} A2,2A_{2,2} \dots A2,KA_{2,K}
\dots
CNC_N AN,1A_{N,1} AN,2A_{N,2} \dots AN,KA_{N,K}

Output

If AtCoder Inc. can achieve its goal, print the minimum total cost required to achieve the goal; otherwise, print -1.


Sample Input 1Copy

Copy
4 3 5
5 3 0 2
3 1 2 3
3 2 4 0
1 0 1 4

Sample Output 1Copy

Copy
9

If you execute the first, third, and fourth development plans, each parameter will be 3+2+0=5,0+4+1=5,2+0+4=63+2+0=5,0+4+1=5,2+0+4=6, all of which are at least 55, so the goal is achieved. The total cost in this case is 5+3+1=95 + 3 + 1 = 9.

It is impossible to achieve the goal at a total cost of 88 or less. Thus, the answer is 99.


Sample Input 2Copy

Copy
7 3 5
85 1 0 1
37 1 1 0
38 2 0 0
45 0 2 2
67 1 1 0
12 2 2 0
94 2 2 1

Sample Output 2Copy

Copy
-1

You cannot achieve the goal no matter what you do. Thus, print -1.



2025-04-23 (Wed)
09:00:03 +00:00