Visiting Singapore
Time limit2sMemory limit256 MB
Choose which days to attend so the events match T in order, paying penalties for skipped events and long idle gaps, to maximize total happiness.
- Level
Medium6 of 10
- Topics
- Dynamic programming, String matching
- Solved
- No attempts yet
Problem
Singapore holds one event per day. The set of possible events is . Attending event increases your happiness by . Let be the list of events held on the days, in order. The same event may appear several times in this list.
You want to attend the events in this order. The same event may also appear several times in . You may fly to Singapore on day and leave on day . You may also skip the trip entirely.
Attending increases your happiness by . Skipping reduces your happiness by .
If you go a run of consecutive days during your stay without attending any event, your happiness is reduced by . Formally, if you attend and with and attend nothing in between, your happiness is reduced by .
Find the maximum happiness you can get.
Input
The first line contains five integers , , , , and . , , and are positive integers. and are negative integers.
The second line contains positive integers .
The third line contains integers . Each is between 1 and .
The fourth line contains integers . Each is between 1 and .
Output
Print a single integer on one line: the total happiness of an optimal schedule.
Constraints
- for all .