Lazy, but honest - Task Scheduling · IZhO 2024 #C

Physics · mechanics

Problem

Somewhere in the world, there is a lazy programmer Batyr. He recently started a new job and wants to make a work plan for the next NN days. On the ii-th day, Batyr gets new bib_i tasks that need to be completed. The company has a regular release etiquette, so all tasks that Batyr receives on the ii-th day must be completed no later than day min⁡(N,i+D−1)\min(N, i+D-1) for a known integer DD. Batyr calculated that if he focuses and works on the ii-th day, he can complete aia_i tasks on that day, but no more. Alternatively, if Batyr decides not to work on the ii-th day, he will not complete any tasks on that day. It should be noted that on the ii-th day, Batyr can only perform tasks from days j≤ij \leq i. Although Batyr is a lazy programmer, he is honest. Therefore, he must complete all his tasks. What is the minimum number of days Batyr needs to work in order to complete all his tasks? Input: The first line contains a single integer tt — the number of test cases. The first line of each test case contains two integers NN and DD (1≤D≤N≤5⋅105)(1 \leq D \leq N \leq 5 \cdot 10^5). The second line of the test case contains NN integers a1,a2,…,aNa_1, a_2, \ldots, a_N (0≤ai≤109)(0 \leq a_i \leq 10^9) — the maximum number of tasks Batyr can complete on the ii-th day. The third line of the test case contains NN integers b1,b2,…,bNb_1, b_2, \ldots, b_N (0≤bi≤109)(0 \leq b_i \leq 10^9) — the number of new tasks appearing on the ii-th day. It is guaranteed that the sum of NN over all test cases does not exceed 5⋅1055 \cdot 10^5. Output: For each test case, output a single integer — the minimum number of days Batyr needs to complete all tasks. If this is not possible, output −1-1.

Browse the problem library