JobPlanner
TCCC07 Sponsor 2 · 2007-07-30 · by andrewzta
Problem Statement
You have m workers numbered 1 through m, and you have n tasks that must be completed. You know which tasks can be performed by each of the workers. If worker i completes t different tasks, he must be paid cost[i]*t2. You would like to minimize the total cost of completing all the tasks.
You will be given a
Constraints
- can will contain between 1 and 50 elements, inclusive.
- All elements of can will contain the same number of characters.
- Each element of can will contain between 1 and 50 characters, inclusive.
- Each element of can will contain only 'Y' and 'N' characters.
- cost will contain the same number of elements as can.
- Each element of cost will be between 1 and 500,000, inclusive.
{"YY","YY"}
{1,2}
Returns: 3
In this case each worker can perform any task. It is better to give one task to the first worker, and another task to the second worker. The total cost is 1 * 12 + 2 * 12 = 3.
{"YY","YY"}
{1,5}
Returns: 4
In this case it is better to give both tasks to the first worker since the second one is too expensive. The total cost is 1 * 22 + 5 * 02 = 4.
{"YN", "YY"}
{1, 5}
Returns: 6
In this case the first worker cannot perform the second task, so we need to use the second worker. The total cost is 1 * 12 + 5 * 12 = 6.
{"YN", "YN"}
{1, 1}
Returns: -1
In this case the second task cannot be completed at all.
{"YY"}
{1}
Returns: 4
Submissions are judged against all 85 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class JobPlanner with a public method int minimalCost(vector<string> can, vector<int> cost) · 85 test cases · 2 s / 256 MB per case