BAT1 - BATMAN1

" Lucius Fox: This conversation used to end with an unusual request.
Bruce Wayne: I'm retired.
Lucius Fox: Well let me show you some stuff anyway. Just for old time's sake.
"

 

Eight years after Harvey Dent's death, the Dent Act allowed eradication of organized crime. BATMAN has disappeared. Wayne enterprises is unprofitable after Bruce discontinued his fusion reactor project. A masked man called Bane who was trained under Ra's al Ghul captures Gordon. Bane attacks the Gotham Stock Exchange, using Bruce's fingerprints in a transaction that bankrupts Wayne.

Now that Gotham City was heading into deep deep trouble, Its time for BATMAN to return.

However, since the company no longer belongs to Bruce Wayne, Mr. Wayne has very little funds to spend on buying his weaponries. Mr Fox head him to the place where all weapons are stored.  

Now these weapons come in batches properly sealed for safety. Each of these batches will have an unbounded number of weapons of different types. To buy these weapons Wayne initially need to pay the price for opening the seal. Then each of these weapons have a cost and a power rating associated with it.  Mr Wayne needs to spend wisely on it to maximize the power rating using  limited amount of money.

People of Gotham, he needs your help for choosing his weaponries.

Lucius Fox: It has a long uninteresting name. I just took to calling it... The Bat, and yes, Mr. Wayne, it does come in black.

Input

t, number of testcases
integers n m k, n: number of batches, m: number of weaponries per batch, k : Money Wayne can spend on weaponries
n integers giving cost of opening the ith batch
n*m numbers denoting cost of jth object from ith batch
n*m numbers denoting the rating of jth object from ith batch

Output

The maximum power rating Wayne could afford 

Constraint:

1 <= n, m <= 20
k <= 1000
cost[i] <= 20
rating[i] <= 100

Example

Input:
1
2 4 20
3 4
3 2 3 2
3 2 3 5
3 2 3 2
4 5 6 5

Output:
40

Added by:Romal Thoppilan
Date:2013-02-06
Time limit:1s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: ASM64
Resource:own problem

hide comments
2024-08-27 05:28:36
AC in one go - O(n*m*k)
2024-05-31 16:30:46
why is o(n*m*k*K) is resulting tle ?
2021-04-01 22:14:41
O(n*k*m) works fine...
Output for tc provided by @Rafail Loizou is 26, and for the tc provided by @learnerinblack is 3589
2021-03-13 19:46:58
@Rafail Loizou

my solution ouput 26 by input testcase you provided. But got WA. is there something wrong?
2020-11-14 17:33:16 Rafail Loizou
!!! WARNING !!!
I got AC with O(n*k*k*m). I followed this complexity's logic by looking at the comments.
1d: until which batch we will use.
2d: until how much money we will spend on opening batches.
3d: until which amount of money we will spend in total ( seals + buying weapons from open batches)
But even if this gets AC I found a test cases that makes this solution not work and I bet if you add this it will make most of the solutions submitted not work. Here is the test case:
1
3 1 14

1 1 1

5
3
7

6
3
20
My solution gives answer 23. And I bet most n*k*k solutions do. But the correct answer here is 26. He can open 1st and 3rd batch and buy a cost 5 weapon and a cost 7 weapon giving 26 total rating as the answer. This problem to actually be solvable without WAs like this that the problem setter did not take into consideration needs 2^n * k * m and add the optimizations to figure out a correct time limit. This problem is a joke just do the n*k*k*m WA solution and you will get AC.
2020-05-26 21:10:21
Please check id 26046604. I don't know why it's giving WA.
2020-02-29 05:37:38
4Dimention dp problem Nice
learn something new
2020-01-25 20:00:31
good problem
top down is <3
2019-11-05 12:39:10
Nice problem !! AC in one go ;p


Last edit: 2019-11-05 12:39:26
2019-03-08 17:44:42
Getting TLE with O(n*k*k) algo.
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.