
ZOJ Problem Set  3453
Doraemon likes to shoot his enemies with sweet bullets. n "enemies" stand in a line, each with a life value l_{i} (the index i increases from left to right side and starts from 1). Each time Doraemon shoots a sweet bullet from the right side. The ith bullet has a "critical range" k_{i}. That is to say, it attacks the first enemy from right side whose life value is equal to or greater than k_{i}. The life value of the attacked enemy will decrease to 1 immediately. However, Doraemon finds a terrible fact that after an enemy is attacked, it will distribute the sweets to his friends and his friends' life value will increase by 1. For the ith enemy, his friends are in a consecutive range from the a_{i}th enemy to the b_{i}th. Note that an enemy may be the friend of himself so that after being attacked his life value will be 2. What's more, if a bullet can't find a targetthere doesn't exist an enemy with life greater or equal than k_{i}, all enemies' life will increase by 1. Now Doraemon wants to know after m bullets were shot, what the maximum life value in all enemies is. InputThe input contains multiple test cases. Each test case begins with a line containing a single integer n (1 ≤ n ≤ 100000) indicating the number of enemies. The following n lines describes enemies, one enemy each line. Each line contains three integers, the initial life value l_{i} (1 ≤ l_{i} ≤ 10000) and his range of friends a_{i} b_{i} (1 ≤ a_{i} ≤ b_{i}≤ n)  that is, enemies with index from a_{i} to b_{i} (inclusive) are all his friends. The following line contains an integer m (1 ≤ m ≤ 100000) indicating the number of bullets Doraemon has shot. The last m lines follows, each with a single integer k_{i} (1 ≤ k_{i} ≤ 10000) describing the bullet's "critical range". Different cases are separated by a blank line. Process to the end of input. OutputFor each test case, output the maximum life value after shooting in a single line. Sample Input3 3 1 2 4 1 3 5 1 1 3 4 2 1 Sample Output6 HintDoraemon suggests that you should use scanf to read data. Author: WAN, Xinyi Contest: ZOJ Monthly, December 2010 