Drying Laundry
Time limit3sMemory limit1024 MB
Each sheet either hangs on one line (slow time) or spans both lines (fast time). For each line length, find the minimal time to dry all sheets, or report -1.
- Level
Hard8 of 10
- Topics
- Dynamic programming, Sorting, Binary search
- Solved
- No attempts yet
Problem
Harry the Beaver runs a hotel and has to wash bed sheets every Sunday night for the next weeks until the tourist season ends. In week , he has freshly washed bed sheets and wants to dry them by hanging them on two parallel clotheslines, each of length . Sheets can hang next to each other but must not overlap. Each sheet is units wide and quite long, so he always hangs it so that it takes up units of a line. The sheets have different drying times because their materials differ, and those times do not depend on their sizes. Sheet needs minutes when hung on one line. If it is hung over both lines at the same time, it dries in minutes, but it also takes up space on the other line. Harry wants to go to sleep as early as possible on Sundays. All sheets must start drying right after washing, so all of them must be hung at the same time. Find the minimal drying time for each week , or report that the sheets cannot all be dried that week.
Input
The first line contains two integers and , the number of sheets and the number of weeks until the end of the tourist season. Each of the next lines contains three space-separated integers , , and , the width, the shorter drying time, and the longer drying time of sheet . Each of the final lines contains one integer , the length of the clotheslines in week .
Output
Print lines. The -th line contains the minimal required drying time for week , or -1 if it is impossible to finish drying the sheets that week. If the minimal drying time is longer than the number of minutes in a week, print it anyway instead of -1.
Constraints
- for all
- for all
- for all