View as PDF

Points: 5
Time limit: 2.0s
Memory limit: 256M

Author:
Problem type

Julia likes avocado trees. She maintains a strip of trees by a river. All of the trees are grown along a straight line. However, Rose the avocado-robber has just made it into town. Rose would like to steal all the avocados from Julia's trees, but she also knows that Julia keeps her trees well guarded. This means that Rose will only get one chance to raid Julia. Additionally, Rose is short, and so can only steal from trees with height at most . Rose has also decided to not attempt to hit all the trees, but will instead focus on one contiguous range of trees (presumably to lower chances of being seen).

Rose has created a list of all the ranges she is considering to steal from. Since she can only steal from one range before having to escape, write a program to find the maximum number of avocados she can steal.

#### Input Specification

The first line will contain three integers: , denoting the number of trees Julia has, , the number of possible ranges Rose has on her list, and , the maximum height Rose can steal from.

The next lines will contain two integers: , denoting the height of the tree at position , and , denoting the avocado yield of that particular tree.

The next lines will contain two integers and , denoting that the range Rose has chosen begins at and ends at (inclusive).

#### Output Specification

Output a single integer, the maximum number of avocados Rose can obtain from a single range.

#### Sample Input

5 2 3
1 3
4 2
3 3
2 1
1 1
1 3
2 5

#### Sample Output

6

#### Explanation for Sample Output

The first range is from tree to tree , which will give Rose avocados since the tree at index is too tall for Rose to steal from. The second range from tree to tree will only yield avocados. Therefore, the maximum number of avocados that can be obtained from a single range is .

• commented on May 25, 2024, 10:29 a.m. edit 3

I have no qualms whatsoever about posting this Python hint: if you're stuck, compare run times in Python 3 vs. PyPy3! Or, check out the About > Tips section of DMOJ to optimise I/O.

• commented on April 21, 2022, 8:25 p.m.

Evil time out! I'm not sure where to look for more speed, any pointers would be most appreciated....

Thanks

• commented on April 21, 2022, 10:51 p.m. edited

This comment is hidden due to too much negative feedback. Show it anyway.

• commented on Feb. 5, 2021, 12:07 a.m. edited

Tfw you misread the problem and spend hours debugging.