PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#BS0000289. Sản xuất nhiều hợp kim nhất (Maximum Number of Alloys)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Sản xuất nhiều hợp kim nhất (Maximum Number of Alloys)

Maximum Number of Alloys

Source: LeetCode

Version: Phuoc Hung OJ Extended

Problem Statement

There are nn metal types and kk machines. Machine ii consumes aija_{ij} units of metal jj per alloy. Initial stock is sjs_j, and each additional unit costs cjc_j. The budget is BB. Select a single machine for all production; mixing machines is forbidden. Maximize the number of alloys.

Input

First line: n,k,Bn,k,B. Next k lines: n integers aija_{ij} per row. Next line: n stocks sjs_j. Last line: n costs cjc_j.

Output

Print the maximum number of alloys.

Subtasks

  • Subtask 1 (20 points): 1≤n,k≤41\le n,k\le4; 0≤B≤1000\le B\le100; 1≤aij,cj≤51\le a_{ij},c_j\le5; 0≤sj≤200\le s_j\le20.
  • Subtask 2 (30 points): 1≤n≤1001\le n\le100; k=1k=1; 0≤B≤1080\le B\le10^8; 1≤aij,cj≤1001\le a_{ij},c_j\le100; 0≤sj≤1080\le s_j\le10^8.
  • Subtask 3 (50 points): 1≤n,k≤1001\le n,k\le100; 0≤B≤1080\le B\le10^8; 1≤aij,cj≤1001\le a_{ij},c_j\le100; 0≤sj≤1080\le s_j\le10^8.

Examples

Input 1

3 2 15
1 1 1
1 1 10
0 0 100
1 2 3

Output 1

5

Explanation

Machine 2 makes five alloys for cost 15, using 50 units of metal 3 from stock. Six alloys already require cost 18 for metals 1 and 2 alone.