Under construction

Still being built. Things may change

Solar Charging

Interview

Time limit0.5sMemory limit512 MB

Summary
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 BB units, and its maximum capacity is CC. On day ii, he plans to use exactly DiD_i units of electricity. If the battery holds at least DiD_i on day ii, he can use appliances from the battery, and the charge drops by DiD_i. No household electricity is used that day, so there is no cost. If he charges the battery on day ii, the charge rises by PiP_i, but it cannot exceed CC. 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 ii the rate per unit is FiF_i, so he pays Di⋅FiD_i \cdot F_i that day.

Under these conditions, Albert uses the electricity he needs each day for the next NN days. After day NN, the battery must hold at least BB, the starting charge. Find the minimum total electricity cost.

Input

The first line contains the number of test cases TT.

The first line of each test case contains NN, BB, and CC, separated by spaces. The second line contains the array PP, the amount the battery can be charged by sunlight each day, separated by spaces. The third line contains the array FF, the electricity rate that changes each day, separated by spaces. The fourth line contains the array DD, 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

  • 1≤T≤101 \le T \le 10
  • 1≤N,C≤10001 \le N, C \le 1000
  • 0≤B≤C0 \le B \le C
  • 1≤i≤N1 \le i \le N for each ii:
    • 1≤Di,Pi≤10001 \le D_i, P_i \le 1000
    • 1≤Fi≤1091 \le F_i \le 10^9

Examples1

  1. Example 1

    Input
    5
    4 0 10
    10 10 10 1
    100 100 100 100
    4 3 2 1
    4 10 10
    10 10 10 1
    100 100 100 100
    4 3 2 1
    4 9 10
    10 10 10 9
    100 100 100 100
    3 3 3 1
    5 3 20
    3 5 3 5 3
    2 10 3 5 8
    5 4 3 4 5
    5 0 1
    1 1 1 1 1
    1000000000 1000000000 1000000000 1000000000 1000000000
    1000 1000 1000 1000 1000
    
    Expected output
    400
    300
    100
    39
    5000000000000