XH Company
Time limit2sMemory limit256 MB
For each query day D, report the length of the shortest suffix ending on day D-1 with the largest average.
- Level
Medium7 of 10
- Topics
- Stack, Prefix sum, Two pointers
- Solved
- No attempts yet
Problem
XH Company sells a children's toy called Jjaero Escape. Myeongwoo works there and records the daily profit and loss.
The shareholders occasionally want to see the recent numbers, and they get angry when the profit looks smaller than they expected. So Myeongwoo picks the stretch of records that makes the average look as high as possible. A missing day in the middle, or a missing day right before the request, draws suspicion, so he has to show a contiguous run of days that ends on the day right before the requested day. The profit of the requested day itself is not known yet, so he cannot show it.
There are daily records . When a shareholder asks on day , Myeongwoo picks one with and shows . Choose so that the average of those values is as large as possible, and report how many records Myeongwoo shows.
Input
The first line contains the number of test cases . Then test cases follow.
The first line of a test case contains the number of recorded days (). The second line contains integers () separated by spaces. The third line contains the number of shareholder requests (). The fourth line contains the requested days () in ascending order.
Output
Print one line per test case. On that line print, in the order the requests are given, how many records Myeongwoo shows, separated by spaces. If several counts reach the maximum average, print the smallest of them.