#C885. Balloon Contest
Balloon Contest
Balloon Contest
You are given N houses, each with a certain number of balloons. The houses are numbered from 1 to N. Your task is to compute the total number of balloons for the houses in a given range and identify the house with the maximum number of balloons in that range. In case multiple houses have the same maximum balloon count, return the one with the smallest index.
More formally, let \(B = [b_1, b_2, \ldots, b_N]\) be an array where \(b_i\) represents the balloon count at the \(i^{th}\) house. Given two integers L and R (with 1-indexing), you need to:
- Calculate the total balloons \(T = \sum_{i=L}^{R} b_i\).
- Find the house index \(k\) (where \(L \leq k \leq R\)) such that \(b_k = \max\{b_L, b_{L+1}, \ldots, b_R\}\). If there are multiple such indices, choose the smallest one.
Input/Output format note: Your program should read from standard input (stdin
) and write the result to standard output (stdout
).
Sample Input:
5
3 12 8 6 4
2 4
Sample Output:
26 2
Note: In the sample above, among houses 2 to 4, the balloon counts are [12, 8, 6]. The total is 26 and the maximum balloon count is 12 at house index 2.
inputFormat
The input consists of three parts:
- A single integer N on the first line, representing the number of houses.
- A line with N space-separated integers, where the \(i^{th}\) integer represents the balloon count at house
i
. - A line with two space-separated integers L and R representing the starting and ending house numbers of the queried range (1-indexed).
outputFormat
Output two space-separated integers: the total number of balloons in the range [L, R] and the house number (index) with the maximum number of balloons in that range. In case of ties for the maximum, the smallest index is returned.
## sample5
3 12 8 6 4
2 4
26 2
</p>