
ZOJ Problem Set  3245
Task You have a big farm, and you want to grow vegetables in it. You're too lazy to seed the seeds yourself, so you've hired n people to do the job for you. Each person works in a rectangular piece of land, seeding one seed in one unit square. The working areas of different people may overlap, so one unit square can be seeded several times. However, due to limited space, different seeds in one square fight each other  finally, the most powerful seed wins. If there are several "most powerful" seeds, one of them win (it does not matter which one wins). There are m kinds of seeds. Different seeds grow up into different vegetables and sells for different prices. As a rule, more powerful seeds always grow up into more expensive vegetables. Your task is to calculate how much money will you get, by selling all the vegetables in the whole farm. Input The first line contains a single integer T (T <= 10), the number of test cases. Each case begins with two integers n, m (1 <= n <= 30000, 1 <= m <= 3). The next line contains m distinct positive integers p_{i} (1 <= p_{i} <= 100), the prices of each kind of vegetable. The vegetables (and their corresponding seeds) are numbered 1 to m in the order they appear in the input. Each of the following n lines contains five integers x1, y1, x2, y2, s, indicating a working seeded a rectangular area with lowerleft corner (x1,y1), upperright corner (x2,y2), with the sth kind of seed. All of x1, y1, x2, y2 will be no larger than 10^{6} in their absolute values.Output For each test case, print the case number and your final income.Sample Input 2 1 1 25 0 0 10 10 1 2 2 5 2 0 0 2 1 1 1 0 3 2 2 Sample Output Case 1: 2500 Case 2: 16 Author: Tang, Wenbin Source: The 2009 ACMICPC Asia Ningbo Regional Online Contest 