All that jazz
Stavroula really likes jazz music. She won the lottery, so she decides to take a trip to New Orleans and attend as many jazz concerts as possible. Help her plan her trip!
In the near future, jazz concerts will be held in New Orleans, and for each concert, the date
on which it will take place is known.
For simplicity reasons, in this problem, we have replaced the dates with positive integers: day
, day
, and so on.
Stavroula hasn't decided yet when she will go or how many days she will stay in New Orleans.
She wants your help in deciding, by answering a total of queries, each of the form: "If I go for
days to New Orleans and plan my departure optimally, how many concerts can I attend?"
Consider that Stavroula will be able to attend all concerts taking place during her entire stay in New Orleans, including the first and last days. Also, she can attend more than one concert on the same day.
Problem
Develop a program in one of the IOI languages (PASCAL, C, C++, Java) that reads the information about the concerts and Stavroula's queries and provides the answers.
Input Files:
The input files named allthatjazz.in are text files with the following structure: The first line contains a positive integer : the number of concerts.
The second line contains exactly
integers
(where
), separated in pairs by a single space: the day each of the
concerts is held.
The third line contains a positive integer: the number of questions
.
The fourth line contains exactly
integers
(where
), separated in pairs by a single space: the duration in days of Stavroula's trip for the
-th question.
Output Files:
The output files named allthatjazz.out are text files with the following structure.
They must contain exactly lines, where each line contains exactly one integer: the answer to the
-th question, in order.
Constraints:
- 1
1.000.000, 1
1.000.000 and
2.000.000
- 1
1.000.000.000 for each
, where 1
- 1
1.000.000.000 for each
, where 1
Examples of Input - Output Files:
STDIN (allthatjazz.in)
6
7 4 2 5 4 3
7
3 4 2 1 6 2 5
STDOUT (allthatjazz.out)
4
5
3
2
6
3
5
Explanation of the example:
There will be a total of concerts. The first one will be on day
, the second on day
, the third on day
, and so on. Note that on day
, two concerts will take place. Also, on some days, for example, on day
and day
, no concerts will be held.
We need to answer questions:
- For
, meaning if Stavroula stays for
days in New Orleans, how many concerts can she attend at most? If she arrives on day
and stays until day
(a total of
days), she can attend a maximum of
concerts: one on day
, one on day
, and two on day
. This is the maximum she can achieve for a stay of
days.
- For
, from day
to day
, a total of
concerts.
- For
, from day
to day
, a total of
concerts.
- For
, only on day
, a total of
concerts.
- For
, from day
to day
, a total of
concerts.
- For
, the same question has already been answered.
- For
, from day
to day
, a total of
concerts.
Notes:
Formatting: In both the input and the output, each line terminates with a newline
character.
Maximum execution time: 1sec.
Maximum available memory: 64MB.
Headers in the source code: At the beginning of your source code, you should use the following headers.
(* USER: username
LANG: PASCAL
TASK: allthatjazz *)
for PASCAL coders
/* USER: username
LANG: C
TASK: allthatjazz */
for C coders
/* USER: username
LANG: C++
TASK: allthatjazz */
for C++ coders
/* USER: username
LANG: Java
TASK: allthatjazz */
for Java coders
# USER: username
# LANG: Python
# TASK: allthatjazz
for Python coders
Comments