SELLPHN2 - Mobile Company 2

On day 1, a mobile manufacturing company bought L quantities of raw materials which can produce exactly L mobile phones. The raw materials are then transported to factories.

The company owns M factories located at various locations where these raw materials are converted into mobile phones. ith factory is capable of producing at most F[i] mobile phones provided the availability of raw materials.

The manufactured mobile phones can be transported to N shops at various locations where these mobile phones are sold. Each shop has a selling capability. ith shop can sell at most S[i] mobile phones in a day. You are given a 2D map of order MxN. ith factory can transport at most map[i][j] mobile phones to jth shop.

Find the maximum number of mobile phones that can be sold by the company on day 1. For simplicity you can assume that the time taken for transportation of raw materials and mobiles as 0.

Input

The first line consists of an integer t, the number of test cases. For each test case, the first line consists of 3 integers L, M and N. The next line consists of M integers representing the array F. The next line consists of N integers representing the array S. The next M lines represent the map.

Output

For each test case, find the maximum number of mobile phones that can be sold by the company on day 1.

Constraints

1 <= t <= 100

1 <= L <= 1000

1 <= M <= 200

1 <= N <= 200

0 <= F[i] <= 1000

0 <= S[i] <= 1000

0 <= map[i][j] <= 1000

Sample

Input
2
5 2 2
3 5
2 3
1 2
1 0
3 3 1
3 4 4
4
1
2
2

Output
4
3

See Also: Mobile Company 1


Added by:cegprakash
Date:2015-01-14
Time limit:10s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All

hide comments
2016-02-08 11:01:45 [Rampage] Blue.Mary
You need a fast [spoiler] library, not need to consider time complexity.

Last edit: 2016-07-29 21:57:43
2015-08-28 13:48:13 Rishav Goyal
what is the expected order in it ? 200^2*1000*T is failing.

Last edit: 2015-08-28 13:54:17
2015-05-30 00:31:29 (Tjandra Satria Gunawan)(曾毅昆)
Finally!! FirstPlace!!! ^_^
2015-05-29 23:59:09 (Tjandra Satria Gunawan)(曾毅昆)
phew, finally AC..
Hard Problem *_* I'm still unfamiliar with [spoiler]..

Last edit: 2016-07-29 21:58:12
2015-04-24 22:14:11 Eddy R. Morales Perez
My 700th classical ;)
2015-04-07 14:42:31 785227
My 300th classical, A milestone problem _/\_
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.