#x1058. CF1305H Kuroni the Private Tutor

CF1305H Kuroni the Private Tutor

Kuroni the Private Tutor

题面翻译

题目描述

Kuroni 举行了一场考试,有 nn 道试题, mm 位学生参加的考试,每一题的分值为 1 分。第 ii 个问题至少有 lil_i 人答对,最多有 rir_i 人答对。此外,你还知道所有学生的总成绩为 tt

你浏览了考试的最终排名,学生的排名从 1 到 mm ,第 1 名的学生得分最高,第 mm 名的学生得分最低。

同时,你知道排名 pip_i 的学生的得分为 sis_i

Kuroni 希望你回答:

  • 最多能有多少人并列第一;
  • 在有尽量多的人并列第一的情况下,第一名的分数最高是多少。

输入格式

第一行两个整数 nn ,mm

接下来 nn 行,每行两个整数,表示 lil_irir_i

下面一行一个整数 qq

接下来 qq 行,每行两个整数,表示 pip_isis_i

最后一行一个整数 tt

所有变量的意义同题目描述。

输出格式

一行两个整数,为所求答案,如果无解,请输出 -1 -1 。

数据范围

1n1 \le n , m105m \le 10^5

0lirim0 \le l_i \le r_i \le m

0qm0 \le q \le m

1pim1 \le p_i \le m , 0sin0 \le s_i \le n

0tnm0 \le t \le nm

题目描述

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 n n questions, and m m students have taken the exam. Each question was worth 1 1 point. Question i i was solved by at least li l_i and at most ri r_i students. Additionally, you know that the total score of all students is t t .

Furthermore, you took a glance at the final ranklist of the quiz. The students were ranked from 1 1 to m m , where rank 1 1 has the highest score and rank m m has the lowest score. Ties were broken arbitrarily.

You know that the student at rank pi p_i had a score of si s_i for 1iq 1 \le i \le q .

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 1 1 , and the maximum possible score for rank 1 1 achieving this maximum number of students.

输入格式

The first line of input contains two integers ( 1n,m105 1 \le n, m \le 10^{5} ), denoting the number of questions of the exam and the number of students respectively.

The next n n lines contain two integers each, with the i i -th line containing li l_{i} and ri r_{i} ( 0lirim 0 \le l_{i} \le r_{i} \le m ).

The next line contains a single integer q q ( 0qm 0 \le q \le m ).

The next q q lines contain two integers each, denoting pi p_{i} and si s_{i} ( 1pim 1 \le p_{i} \le m , 0sin 0 \le s_{i} \le n ). It is guaranteed that all pi p_{i} are distinct and if pipj p_{i} \le p_{j} , then sisj s_{i} \ge s_{j} .

The last line contains a single integer t t ( 0tnm 0 \le t \le nm ), 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 1 1 , and the maximum possible score for rank 1 1 achieving this maximum number of students. If there is no valid arrangement that fits the given data, output 1 -1 1 -1 .

样例 #1

样例输入 #1

5 4
2 4
2 3
1 1
0 1
0 0
1
4 1
7

样例输出 #1

3 2

样例 #2

样例输入 #2

5 6
0 6
0 6
2 5
6 6
4 6
1
3 3
30

样例输出 #2

-1 -1

提示

For the first sample, here is one possible arrangement that fits the data:

Students 1 1 and 2 2 both solved problems 1 1 and 2 2 .

Student 3 3 solved problems 2 2 and 3 3 .

Student 4 4 solved problem 4 4 .

The total score of all students is T=7 T = 7 . Note that the scores of the students are 2 2 , 2 2 , 2 2 and 1 1 respectively, which satisfies the condition that the student at rank 4 4 gets exactly 1 1 point. Finally, 3 3 students tied for first with a maximum score of 2 2 , and it can be proven that we cannot do better with any other arrangement.