Solar Charging
InterviewTime limit0.5sMemory limit512 MB
Each day the battery is either charged by sunlight or used, and the task is to find the minimum electricity cost while ending at or above the starting charge.
- Level
Medium5 of 10
- Topics
- Dynamic programming, Implementation
- Solved
- No attempts yet
Problem
Albert recently bought a battery that is charged by solar power, and he wants to use it to save electricity. The battery cannot be charged and used at the same time. So each morning, he decides once per day whether to charge the battery or use it. Changing the decision more often is too much trouble.
The battery currently holds units, and its maximum capacity is . On day , he plans to use exactly units of electricity. If the battery holds at least on day , he can use appliances from the battery, and the charge drops by . No household electricity is used that day, so there is no cost. If he charges the battery on day , the charge rises by , but it cannot exceed . Since charging and using cannot happen together, he must use household electricity that day and pay for it. The electricity rate changes every day. On day the rate per unit is , so he pays that day.
Under these conditions, Albert uses the electricity he needs each day for the next days. After day , the battery must hold at least , the starting charge. Find the minimum total electricity cost.
Input
The first line contains the number of test cases .
The first line of each test case contains , , and , separated by spaces. The second line contains the array , the amount the battery can be charged by sunlight each day, separated by spaces. The third line contains the array , the electricity rate that changes each day, separated by spaces. The fourth line contains the array , the amount of electricity used each day, separated by spaces.
Output
For each test case, print the minimum electricity cost on its own line.
Constraints
- for each :