{"raw_statement":[{"iden":"problem statement","content":"Solve the following problem for $T$ test cases.\nYou are currently at coordinate $0$ on a number line, and you want to reach coordinate $L$.\nYou will use a car for the movement. This car runs on two types of fuel: types $1$ and $2$. For each type, the car has a fuel tank of that type with a capacity of $C$ liters. Currently, both fuel tanks are full. The car can consume $x$ liters of either type of fuel (where $x$ is any positive integer not exceeding the remaining fuel) to move $x$ units in any direction on the number line. You can choose which type of fuel to use for each movement.\nThere are $N$ fuel stations on the number line. The $i$\\-th fuel station is located at coordinate $X_i$. When the car is exactly at coordinate $X_i$, you can buy type-$K_i$ fuel at a cost of $1$ per liter. Of course, you cannot buy more fuel than allowed by the tank capacity.\nDetermine whether it is possible to reach coordinate $L$. If it is possible, find the minimum total cost of purchasing fuel."},{"iden":"constraints","content":"*   $1 \\leq T \\leq 250000$\n*   $1 \\leq N \\leq 5000$\n*   $1 \\leq L \\leq 10^9$\n*   $1 \\leq C \\leq 10^9$\n*   $0 < X_1 < X_2 < \\cdots < X_N < L$\n*   $K_i=1$ or $2$\n*   The sum of $N^2$ across all test cases in a single input does not exceed $5000^2$.\n*   All input values are integers."},{"iden":"input","content":"The input is given from Standard Input in the following format:\n\n$T$\n$case_1$\n$case_2$\n$\\vdots$\n$case_T$\n\nEach test case is given in the following format:\n\n$N$ $L$ $C$\n$X_1$ $X_2$ $\\cdots$ $X_N$\n$K_1$ $K_2$ $\\cdots$ $K_N$"},{"iden":"sample input 1","content":"5\n1 10 4\n7\n1\n1 10 6\n7\n1\n2 12 3\n5 7\n1 1\n2 12 3\n5 7\n1 2\n20 749013197 23809523\n46981984 70791437 118235723 132421762 180040807 203849360 251468335 275277857 322889975 346699150 394318091 418113855 465732891 489532137 537144103 558852533 606466719 630275002 677584754 701394209\n1 2 2 1 1 2 1 2 1 2 2 1 2 1 2 1 1 2 1 2"},{"iden":"sample output 1","content":"2\n0\n-1\n6\n585545066743659\n\nLet us explain the first test case. You can reach coordinate $L$ with a cost of $2$ as follows:\n\n*   Consume $3$ liters of type-$1$ fuel to move from coordinate $0$ to $3$. The remaining type-$1$ fuel is $1$ liter.\n*   Consume $4$ liters of type-$2$ fuel to move from coordinate $3$ to $7$. The remaining type-$2$ fuel is $0$ liters.\n*   Buy $2$ liters of type-$1$ fuel at the fuel station. The remaining type-$1$ fuel is $3$ liters.\n*   Consume $3$ liters of type-$1$ fuel to move from coordinate $7$ to $10$. The remaining type-$1$ fuel is $0$ liters.\n\nIt is impossible to reach coordinate $L$ with a cost less than $2$. Thus, the answer is $2$."}],"translated_statement":null,"sample_group":[],"show_order":["default"],"formal_statement":null,"simple_statement":null,"has_page_source":true}