AlgoUniversity
  • Go Back
Discussion
Jobs And Profits :

Author

Ujjwal Rana

Difficulty Level : Hard

Submissions : 296

Asked In : Uber

Marks :10

: 5 | : 12

There are some job opportunities in one company. And there are some candidates for these jobs. Candidate can be hired for the ith job if he has all skills that are needed for this job. There are some distinct skills that can be needed for jobs. The company needs only one person for each job. Moreover, each candidate can be hired only for one job and the profit of hiring somebody for the ith job is $$$profits[i]$$$ . The profit of hiring for the set of jobs equals to the sum of profits of each job in the set. For the empty set, it's 0. Your task is to calculate a maximum profit after hiring a subset of candidates for a subset of jobs.

Input

The first line contains $$$3$$$ integers $$$N,M$$$ and $$$K$$$ ($$$1 \leq N,M,K \leq 50$$$) - Number of jobs, number of candidates and total skills respectively. Then for the next $$$N$$$ lines of the input, each line contains a string of length $$$K$$$. If the $$$i^{th}$$$ character of the $$$j^{th}$$$ string is $$$1$$$, it means that the $$$j^{th}$$$ job requires $$$i^{th}$$$ skill. Then for the next $$$M$$$ lines of the input, each line contains a string of length $$$K$$$. If the $$$i^{th}$$$ character of the $$$j^{th}$$$ string is $$$1$$$, it means that the $$$j^{th}$$$ candidate has $$$i^{th}$$$ skill. Then the next line contains $$$N$$$ integers representing the profit for each job.

Output

Print the maximum profit that the company can possibly make

Examples

Input
2 3 4
1 0 1 1
1 1 0 1
1 0 1 0
1 0 1 1
1 1 1 1
3 5
Output
8
Input
2 2 2
1 0
0 1
1 0
1 1
666674 260479
Output
927153

You need to login to view your submissions.

You need to login to view all submissions.

Loading...

Result : Executed

Loading...

Feel something is wrong with the test cases?

Result : Accepted

Test Cases :

You need to Log In
We're glad that you want to attempt this problem!

But to Run or Submit the Problem, you need to Log In.

Continue to Log In
Challenge Submitted!

Your challenge has been submitted successfully.

You will get a response soon via WhatsApp or Email.

Challenge
Facing issue while trying to solve the problem! Don't worry, we got you covered!

Do let us know your issue.

Looks good!
Please enter your issue / feedback.

How do we get in touch with you?
Looks good!
Please enter your phone no.
Looks good!
Please enter your email address.