IOI Manju
InterviewTime limit1sMemory limit256 MB
Choose boxes and fill them with the priciest manju so packed value minus box cost is as large as possible.
- Level
Medium6 of 10
- Topics
- Dynamic programming, Sorting, Prefix sum
- Solved
- No attempts yet
Problem
IOI Inc. made distinct IOI manju. Manju costs yen ().
JOI Inc. offers box types. Box () holds up to manju and costs yen. IOI orders between 0 and box types, one of each chosen type, packs manju into them, and sells each packed set for the sum of manju prices inside.
If every set sells, what is the maximum profit (total manju sales minus total box costs)? Manju left unpacked do not affect profit.
Input
- Line 1: , .
- Next lines: .
- Next lines: , .
Output
One integer: maximum profit.
Constraints
- .
- .
- .
- .
- .