luogu#P12101. [NERC2024] Judicious Watching

[NERC2024] Judicious Watching

题目描述

Jill loves having good grades in university, so she never misses deadlines for her homework assignments. But even more, she loves watching the series and discussing it with her best friend Johnny. And unfortunately, today she needs to choose between these two activities!

Jill needs to complete nn homework tasks. The ii-th task would require aia_i minutes to complete and needs to be submitted to the teacher at most did_i minutes from now. Also, there are mm new episodes of the series that Johnny and Jill want to discuss. The jj-th episode lasts ljl_j minutes. Jill can complete tasks in any order, but she needs to watch the episodes in the order they come. Neither completing a homework task nor watching an episode can be interrupted after starting.

Johnny and Jill need to agree on a time tkt_k when they would have a call to discuss the series. They are not sure yet which time to choose. For each possible time, compute the maximum number of episodes Jill could watch before that time while still being able to complete all nn homework tasks in time.

Note that for the purpose of this problem we assume that discussing the series with Johnny at time tkt_k does not consume significant time from Jill and can happen even if she is in the middle of completing any of her homework tasks.

输入格式

There are several test cases in the input. The input begins with the number of test cases TT (1T10001 \le T \le 1\,000).

Each test case starts with a line with three integers nn (1n2000001 \le n \le 200\,000) --- the number of homework tasks, mm (1m2000001 \le m \le 200\,000) --- the number of episodes, and qq (1q2000001 \le q \le 200\,000) --- the number of possible times for the call with Jill.

The second line contains nn integers aia_i (1ai1091 \le a_i \le 10^9) --- the number of minutes it takes to complete the task. The next line contains nn integers did_i (1di10151 \le d_i \le 10^{15}) --- the deadline before which this task must be completed. The next line contains mm integers ljl_j (1lj1091 \le l_j \le 10^9) --- the length of episodes in the order they need to be watched. The next line contains qq integers tkt_k (1tk10151 \le t_k \le 10^{15}) --- the possible times of call with Jill.

It is possible to complete all tasks within their respective deadlines.

The sum of each of nn, mm, qq over all test cases in input doesn't exceed 200000200\,000.

输出格式

For each test case output a single line with qq integers --- for each possible time tkt_k the maximum number of episodes Jill can watch.

2
1 2 3
10
15
5 5
5 15 20
3 4 5
8 100 8
10 150 20
2 32 1 1
9 200 51 50 10
1 1 2
1 4 2 2 1