#P1305H. Kuroni the Private Tutor
Kuroni the Private Tutor
Description
As a professional private tutor, Kuroni has to gather statistics of an exam. Kuroni has appointed you to complete this important task. You must not disappoint him.
The exam consists of questions, and students have taken the exam. Each question was worth point. Question was solved by at least and at most students. Additionally, you know that the total score of all students is .
Furthermore, you took a glance at the final ranklist of the quiz. The students were ranked from to , where rank has the highest score and rank has the lowest score. Ties were broken arbitrarily.
You know that the student at rank had a score of for .
You wonder if there could have been a huge tie for first place. Help Kuroni determine the maximum number of students who could have gotten as many points as the student with rank , and the maximum possible score for rank achieving this maximum number of students.
The first line of input contains two integers (), denoting the number of questions of the exam and the number of students respectively.
The next lines contain two integers each, with the -th line containing and ().
The next line contains a single integer ().
The next lines contain two integers each, denoting and (, ). It is guaranteed that all are distinct and if , then .
The last line contains a single integer (), denoting the total score of all students.
Output two integers: the maximum number of students who could have gotten as many points as the student with rank , and the maximum possible score for rank achieving this maximum number of students. If there is no valid arrangement that fits the given data, output .
Input
The first line of input contains two integers (), denoting the number of questions of the exam and the number of students respectively.
The next lines contain two integers each, with the -th line containing and ().
The next line contains a single integer ().
The next lines contain two integers each, denoting and (, ). It is guaranteed that all are distinct and if , then .
The last line contains a single integer (), denoting the total score of all students.
Output
Output two integers: the maximum number of students who could have gotten as many points as the student with rank , and the maximum possible score for rank achieving this maximum number of students. If there is no valid arrangement that fits the given data, output .
Note
For the first sample, here is one possible arrangement that fits the data:
Students and both solved problems and .
Student solved problems and .
Student solved problem .
The total score of all students is . Note that the scores of the students are , , and respectively, which satisfies the condition that the student at rank gets exactly point. Finally, students tied for first with a maximum score of , and it can be proven that we cannot do better with any other arrangement.