Kimchi
Time limit1sMemory limit256 MB
Pick bury and take-out days at most D apart to maximize aging days times take-out temperature plus crock value while temperatures fall.
- Level
Medium7 of 10
- Topics
- Dynamic programming, Sliding window, Queue
- Solved
- No attempts yet
Problem
You ripen kimchi in a crock for days, from autumn into winter. You bury the kimchi on one day and take it out on that same day or on a later day.
A kimchi master states the conditions for good kimchi.
- The longer the aging time, the better the kimchi tastes.
- Kimchi freezes on cold days, so a higher temperature on the day you take it out makes the kimchi taste better.
- The value of the crock on the day you bury the kimchi affects the taste.
Written as a formula: if you bury the kimchi on day and take it out on day (), the aging time is , and the aging time may be . The taste is then
where is the temperature on day and is the value of the crock on day . Winter is coming, so the temperature only falls, and holds for every .
Kimchi aged for too long is no good, so the aging time must be at most .
Given the temperature and the value of the crock for every day, find the largest taste you can get.
Input
The first line contains the number of days and the upper limit on the aging time . ()
The second line contains the temperatures . Each is a natural number at most , and holds for every with .
The third line contains the crock values . Each is a natural number at most .
Output
Print the largest taste of the kimchi on one line.