## MALD Contest 1 P4 - Scratch Cat and Demolition

View as PDF

Points: 15 (partial)
Time limit: 1.0s
Java 2.0s
Python 3.0s
Memory limit: 512M

Author:
Problem type
Okay, look, we can't do infinite destruction, or else I'm broke

To support the great cult of Mr. Scratch, the founder of ScratchLand, the Scratch Cats decided to demolish the healthcare district of Yuboland to make room for a Great Statue of Mr. Scratch. The healthcare district can be pictured as a number line with buildings, and the building has floors. However, for research purposes, floors in the district contain "Yubonic Plague" specimens.

The Scratch Cat decides to hire Scratch Cat construction workers for his demolition team. They will choose a segment , the range of demolition. During one round, explosives will be laid, and all will be subtracted by . Since the Scratch Cat wants maximum damage, this process will continue as long as no top floors in the range contain Yubonic Plague specimens. The Scratch Cat is smart enough to know that destroying these floors could result in another pandemic.

Negative heights can potentially be created in demolition rounds. These are the basement floors and count towards destroyed floors. Yuboland buildings have so many basement floors that you can assume there is an "infinite" amount of them.

The Scratch Cat forced hired you to help determine the demolition interval for maximal destruction. Each interval must contain at least building with the virus, or his demolition team will never stop. The Scratch Cat certainly doesn't want to pay for that many explosives.

#### Constraints

All buildings will contain at least floor containing a specimen.

#### Input Specification

The first line will contain two space-separated integers and , the number of buildings and floors.

The next line will contain space-separated integers, the integer will be .

The following lines will contain two space-separated integers and , the building and floor number of the forbidden floor.

#### Output Specification

Output the maximum of floors that can be destroyed. Building and basement floors all count towards floors destroyed.

#### Sample Input

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

#### Sample Output

15

#### Explanation

The optimal way to destroy the buildings is to choose as the interval. Scratch Cat construction workers will keep blowing up this range until the forbidden floor in building is exposed after rounds. This will cause or floors to be destroyed. Note that are all invalid ranges because the Scratch Cat's demolition team will never stop blowing up these ranges.

The diagram above shows the floors destroyed by each round of explosives.

After the unauthorized destruction of floors with illegal explosives, the Scratch Cat was quickly arrested. Despite the arrest of the Scratch Cat, this problem is still in the contest, and you (hopefully) decide to continue working on the problem.