| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
shu problem Fmsn problem Time Limit : 2 seconds Memory Limit : 10MB As you know, MSN is a very common chatting software. Tracy also became a MSN user recently. There's some friends in Tracy's contact list. Tracy wishes to see friends online when she is online so that they can have a talk. Unfortunately, Tracy often finds no friends online. Tracy has to get offline after some time. Tracy expects to see friends online when she is online. So she decides to get friends' online time. But, as you know, our online time can't be steady. This troubled Tracy. However, Tracy is a curious girl, so she decides to solve this problem in another way. Tracy writes a useful program for several months’. This program can report one's online time. Tracy puts it in her friends' computer. When a friend gets online, the program records the time until he or she gets offline. In this way, the program records a time interval. If Tracy is online, she can get this friend's online time interval. But, Tracy finds a serious mistake in her program: when some programs work together, they may confuse each other. That is, program i's report may confuse with program j. So, program i's report may report friend j instead of friend i. Tracy is so lazy that she doesn't want to correct her program. But she still wants to use it. So she thinks out a way to remedy. Tracy thinks that a person spend more time online if he is more active.(Let's believe this theory tentatively.)Tracy gives each of her friends a "active value"Ci. A big value stands for the person is more active. Besides, the online time which programs reported is recorded as Si.(Attention, only when both Tracy and a friends are online can Tracy got the report in current time.) Tracy wants to know which friend does program i report. If program i reports friend j, let "difference value" Di = abs (Ci – Si). Tracy wants to find a best arrangement through making the sum of Di minimal. So she finds you to help her find the best arrangement. If the minimal sum is larger than "limit”, it means that the theory which Tracy believes isn't reliable, so that this program becomes not reliable too. To make this problem more easily, Tracy only interests in the friends who are n' most active or spend n’ most time online. That is, you only need to consider n' programs which report the most Si. Input: The input file contains several test cases. For each test cases: the first line includes 3 numbers: n(1<=n<=2000), n'(1<=n'<=100), limit(0<=limit<=10^9). n means we have n friends and n programs. the next line: first number m(m<=300), means Tracy's online time interval. Following 2*m number, each pair (l, r) stands for a time interval [l, r]. We promise that intervals may not intersect. the following n lines: for ith line, first number m(m<=300), means program i reports m intervals. following 2*m number, each pair stands for a time interval. We promise that intervals may not intersect. the following n' lines, for ith line, contains a number Ci(0<=Ci<=10^9). All the time starts from time 1 and won't exceed 10^5. Output: the first line contain a number stands for the minimal sum of Di. If this value exceeds limit, you should output another line with words "Poor Tracy". Sample Input 1: 3 3 5 2 4 10 19 20 2 3 8 10 11 3 1 3 8 9 15 20 3 1 9 10 15 19 19 7 8 1 Sample Output 1: 4 Details: Si = 6,4,8, Ci = 7,8,1. For arrangement program1->friend1, program2->friend3, program3->friend2, the minimal sum of Di = 4. Sample Input 2: 3 2 1 2 4 10 19 20 1 5 11 3 1 3 8 9 15 20 1 1 10 8 5 Sample Output 2: 2 Poor Tracy Details: considering Si = 6,7, Ci = 8,5. For arrangement program1->friend3, program2->friend2, the minimal sum of Di = 2.But this value exceed limit. Hint: Huge input, scanf(c++) and BufferedReader(Java) is recommended! Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator