Judicious Watching

시간 제한3초메모리 제한2048 MB

요약
각 시각마다 모든 숙제를 마감 안에 끝내면서 볼 수 있는 에피소드의 최대 개수를 구한다.
난이도

어려움10점 중 8점

유형
그리디, 정렬, 누적 합, 이분 탐색
정답자
아직 제출이 없습니다

문제

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 a_ia\_i minutes to complete and needs to be submitted to the teacher at most d_id\_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 l_jl\_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 t_kt\_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 t_kt\_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 (1≤T≤1,0001 \le T \le 1\\,000).

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

The second line contains nn integers a_ia\_i (1≤a_i≤1091 \le a\_i \le 10^9) --- the number of minutes it takes to complete the task. The next line contains nn integers d_id\_i (1≤d_i≤10151 \le d\_i \le 10^{15}) --- the deadline before which this task must be completed. The next line contains mm integers l_jl\_j (1≤l_j≤1091 \le l\_j \le 10^9) --- the length of episodes in the order they need to be watched. The next line contains qq integers t_kt\_k (1≤t_k≤10151 \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 200,000200\\,000.

출력

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

예제1

  1. 예제 1

    입력
    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