P-22 is ready for his Closeup
Time limit5sMemory limit1024 MB
Given camera setups and P-22 sightings by time and location, find the largest glamour of a location where both happen at the same time.
Problem
P-22 rose to national fame when Steve Winter published a photo of P-22 in front of the Hollywood Sign in National Geographic. To do so, Winter spent 15 months placing motion-activated cameras in the park, trying to understand P-22's movements. After all, Griffith Park is pretty big, so going to a random spot at a random time was unlikely to result in meeting P-22. But if you repeat a random attempt often enough, there is a decent chance you will succeed at least once. Here, you are given a list of where Winter set up his camera at various times, and where P-22 was at various times. Find the most glamorous shot of P-22 that Winter captured.
Input
The first line contains the number of input data sets, followed by data sets, each of the following form:
The first line contains three integers , . is the number of locations which Winter considered, is the number of times he set up a camera, and is the number of recorded positions for P-22.
Next is a line with integers , where is the glamour of getting a shot in location . Next, there are lines, each describing a integer time and location for a camera setup. There may be multiple camera setups at the same time. Finally, there are lines, each describing the integer time and location where P-22 was known to have been. There will not be two sightings at the same time. All input numbers fit in a 32-bit integer.
Output
For each data set, output "Data Set x:" on a line by itself, where is its number. Then, output the maximum glamour of any possible shot. A shot is possible if P-22 was in a location at the same time as a camera was set up there. In that case, the shot produced has glamour . If P-22 was never in a spot where there was a camera, then the maximum glamour is 0.
Each data set should be followed by a blank line.