## LCC '23 Contest 2 J3 - Underwater Scales

View as PDF

Points: 5 (partial)
Time limit: 5.0s
Memory limit: 256M

Author:
Problem type

Macduff, overwhelmed by the vast amount of health potions, gets transported to another dimension! However, this place takes place underwater, where the special water allows them to breathe, look around, and move as if walking on land. Macduff, becoming entranced by the magical water, is totally, utterly, shocked.

I CAN BREATHE!! I can see! I- I can do everything! I could cure cancer, solve world hunger- Wait ...

However, in that split second, he loses sight of Macbeth!

Knowing that Macbeth is somewhere over the positions in front of him, he wants to know the range of the direction which Macbeth is headed in. Thankfully, he mysteriously knows the individual weight, , of each position. He also just so happens to know that Macbeth weighs .

Macduff suspects ranges which Macbeth could be in, and so he wants to know the sum of each range, from to . Out of all these ranges, he also wants to know the smallest sum that is greater than or equal to Macbeth's weight, or uh oh if this sum doesn't exist.

#### Input Specification

The first line will contain integer N, W, and Q, representing the number of positions, Macbeth's weight, and the number of questions that Macduff might have respectively.

The next line will contain N integers, representing the weight of the th position.

The next lines will contain two numbers, and , the left and right range (inclusive). These numbers will be 1-indexed.

#### Output Specification

Print lines, representing the total sum of the positions from to for each query.

The next line should contain the smallest sum given by the ranges that is greater than or equal to Macbeth's weight, or uh oh if none exists.

#### Sample Input 1

5 100 10
10 50 100 30 90
1 4
2 5
1 3
2 2
4 5
1 4
3 5
2 5
5 5
2 4

#### Sample Output 1

190
270
160
50
120
190
220
270
90
180
120

#### Sample Input 2

2 1000000000 1
10 10
1 2

#### Sample Output 2

20
uh oh