## DMOPC '19 Contest 4 P5 - Financial Trouble

View as PDF

Points: 17 (partial)
Time limit: 1.2s
Memory limit: 256M

Author:
Problem type

After days of reckless spending, Zawaex has found himself in some deep trouble, and is close to going into debt. He currently has dollars left and he finds a list of events that he had predicted would happen to him over the next few days. The th event can be characterized by a single integer , the amount of money in dollars that he would gain from it. (If was negative, he would instead lose money). If Zawaex's amount of money were to become negative after an event, he would instead "borrow" enough money from his friend so that he would end up with dollars after the event. Since Zawaex has a horrible memory, he doesn't know which events has already happened to him. He also doesn't know when he will be able to find employment and get out of this financial crisis. As such, he wants to know how many times he would need to "borrow" money from a friend and how much money he would be left with at the end for different scenarios where a scenario is defined as a contiguous subsequence of the original events. Being uncertain about his future, Zawaex has turned to you for help.

#### Input Specification

The first line contains three space-separated integers, , , and .
The second line contains space-separated integers, .
lines will follow, each of which will contain two space-separated integers, and , denoting the scenario that is the contiguous subsequence between the th and th events.

#### Output Specification

For each query, output on a new line two space-separated integers, the amount of money that he will be left with in the end and the amount of times that Zawaex has to "borrow" money from his friend.

#### Constraints

It is only necessary to determine the amount of money Zawaex will end up with at the end.
For this subtask, your answer will be accepted as long as the first integer in each line is correct. Note that you must still print two integers on each line.

#### Sample Input

5 10 5
4 -7 -8 2 -3
1 5
2 3
1 3
2 4
3 5

#### Sample Output

0 2
0 1
0 1
2 1
1 0

#### Explanation for Sample Output

For the first query, he ends up with dollars after the first events, and then needs to "borrow" money after the third event. The dollars he gains from the fourth event is not enough for the dollars he stands to lose from the fifth event, thus he needs to borrow money once again.

0 42384
1 325