Project staffing
Time limit1sMemory limit128 MB
Assign at most n hired workers to m projects so the total expected profit from rewards, fines, and conditional wages is maximal.
- Level
Medium5 of 10
- Topics
- Dynamic programming, Probability, Math
- Solved
- No attempts yet
Problem
A company wants to finish projects this week. To do that it can hire at most outside workers from an employment agency, each on a one week contract.
One outside worker is paid salary euros. If the project that the worker was put on does not finish in time, the company pays that worker nothing.
For every project the company knows from experience the probability that the project finishes within the week, as a function of how many workers are on it. The probabilities are given as percentages , where () is the project number and is the number of workers on it. When nobody works on project , the probability is 0 percent.
If project finishes within the week, the company earns reward() euros. If it misses the deadline, the company pays a fine of punishment() euros.
Let () be the probability that a job finishes in time, let be the profit in that case, and let be the (negative) profit when the job is late. The expected profit for that job is .
The company decides how many outside workers to hire and how to spread them over the projects so that the total expected profit at the end of the week is as large as possible. The optimal number of workers is the total number of people needed to reach that maximal expected profit. Compute that number. At most people are available, and a hired person works on exactly one project, so the total is the sum of the workers assigned to the projects.
Input
The first line contains the number of test cases. Each test case has this format.
- One line with the number of projects . ()
- One line with the maximal number of available workers . ()
- One line with salary, the pay of one worker in euros. salary is an integer between 0 and 1000.
- lines, one per project. Line holds integers , followed by reward and punishment for project . Every percentage is an integer between 0 and 100, and reward and punishment are amounts in euros between 0 and 100000. All values on a line are separated by single spaces.
Output
Print two lines for every test case.
- The first line holds the maximal expected profit in eurocents. The percentages are whole numbers and the amounts are whole euros, so this value is always an integer number of eurocents.
- The second line holds the total number of outside workers that must be hired to reach that maximal expected profit. If several different totals reach it, print all of them in increasing order, separated by single spaces.