#P9557. [SDCPC2023] Building Company

[SDCPC2023] Building Company

题目描述

You're the boss of a building company. At the beginning, there are gg types of employees in the company, and different types of employees have different occupations. For the ii-th type of employees, their occupation can be numbered as tit_i and there are uiu_i employees in total.

There are nn building projects in the market waiting to be undertaken. To undertake the ii-th project, your company must meet mim_i requirements. The jj-th requirement requires that your company has at least bi,jb_{i, j} employees whose occupation is ai,ja_{i, j}. After undertaking the project, your company will become more famous and will attract kik_i types of employees to join your company. The occupation of the jj-th type of employees is ci,jc_{i, j} and there are di,jd_{i, j} employees in total.

You can undertake any number of projects in any order. Each project can be undertaken at most once. Calculate the maximum number of projects you can undertake.

Note that employees are not consumables. After undertaking a project the number of employees in your company won't decrease.

输入格式

There is only one test case in each test file.

The first line of the input first contains an integer gg (1g1051 \le g \le 10^5) indicating the number of types of employees in the company at the beginning. Then gg pairs of integers t1,u1,t2,u2,tg,ugt_1, u_1, t_2, u_2, \cdots t_g, u_g follow (1ti,ui1091 \le t_i, u_i \le 10^9), where tit_i and uiu_i indicate that there are uiu_i employees whose occupation is tit_i. It's guaranteed that for all 1i<jg1 \le i < j \le g we have titjt_i \ne t_j.

The second line contains an integer nn (1n1051 \le n \le 10^5) indicating the number of projects waiting to be undertaken.

For the following 2n2n lines, each two lines describe a project.

The (2i1)(2i - 1)-th line first contains an integer mim_i (0mi1050 \le m_i \le 10^5) indicating the number of requirements to undertake the ii-th project. Then mim_i pairs of integers $a_{i, 1}, b_{i, 1}, a_{i, 2}, b_{i, 2}, \cdots, a_{i, m_i}, b_{i, m_i}$ follow (1ai,j,bi,j1091 \le a_{i, j}, b_{i, j} \le 10^9) where ai,ja_{i, j} and bi,jb_{i, j} indicate that the company is required to have at least bi,jb_{i, j} employees whose occupation is ai,ja_{i, j}. It's guaranteed that for all 1x<ymi1 \le x < y \le m_i we have ai,xai,ya_{i, x} \ne a_{i, y}.

The 2i2i-th line first contains an integer kik_i (0ki1050 \le k_i \le 10^5) indicating the number of types of employees to join the company after undertaking the ii-th project. Then kik_i pairs of integers $c_{i, 1}, d_{i, 1}, c_{i, 2}, d_{i, 2}, \cdots, c_{i, k_i}, d_{i, k_i}$ follow (1ci,j,di,j1091 \le c_{i, j}, d_{i, j} \le 10^9) where ci,jc_{i, j} and di,jd_{i, j} indicate that there are di,jd_{i, j} employees whose occupation is ci,jc_{i, j} joining the company. It's guaranteed that for all 1x<yki1 \le x < y \le k_i we have ci,xci,yc_{i, x} \ne c_{i, y}.

It's guaranteed that neither the sum of mim_i nor the sum of kik_i will exceed 10510^5.

输出格式

Output one line containing one integer indicating the maximum number of projects you can undertake.

题目大意

【题目描述】

您是一家建筑公司的老板。一开始,公司共有 gg 类员工,每一类员工都属于一个工种。第 ii 类员工的工种编号为 tit_i,共有 uiu_i 人。

市场上共有 nn 项工程等待承接。想要承接第 ii 项工程,您的公司需要满足 mim_i 项要求,其中第 jj 项要求您的公司至少有工种编号为 ai,ja_{i, j} 的员工 bi,jb_{i, j} 人。承接该工程后,您的公司将会更加有名,并吸引 kik_i 类员工加入公司,其中第 jj 类员工的工种编号为 ci,jc_{i, j},共有 di,jd_{i, j} 人。

您可以按任意顺序承接任意数量的工程,每项工程最多只能被承接一次。求最多能承接多少工程。

请注意:员工不是消耗品。承接一项工程后,员工的数量不会减少。

【输入格式】

每个测试文件仅有一组测试数据。

第一行首先输入一个整数 gg1g1051 \le g \le 10^5)表示一开始公司内员工的种类数。接下来输入 gg 对整数 t1,u1,t2,u2,tg,ugt_1, u_1, t_2, u_2, \cdots t_g, u_g1ti,ui1091 \le t_i, u_i \le 10^9),其中 tit_iuiu_i 表示一开始工种编号为 tit_i 的员工共有 uiu_i 人。保证对于所有 1i<jg1 \le i < j \le gtitjt_i \ne t_j

第二行输入一个整数 nn1n1051 \le n \le 10^5)表示等待承接的工程数量。

对于接下来 2n2n 行,每两行描述一项工程。

(2i1)(2i - 1) 行首先输入一个整数 mim_i0mi1050 \le m_i \le 10^5)表示承接第 ii 项工程有几项要求。接下来输入 mim_i 对整数 $a_{i, 1}, b_{i, 1}, a_{i, 2}, b_{i, 2}, \cdots, a_{i, m_i}, b_{i, m_i}$(1ai,j,bi,j1091 \le a_{i, j}, b_{i, j} \le 10^9),其中 ai,ja_{i, j}bi,jb_{i, j} 表示公司至少要有工种编号为 ai,ja_{i, j} 的员工 bi,jb_{i, j} 人。保证对于所有 1x<ymi1 \le x < y \le m_iai,xai,ya_{i, x} \ne a_{i, y}

2i2i 行首先输入一个整数 kik_i0ki1050 \le k_i \le 10^5)表示承接第 ii 项工程之后有几类员工加入公司。接下来输入 kik_i 对整数 $c_{i, 1}, d_{i, 1}, c_{i, 2}, d_{i, 2}, \cdots, c_{i, k_i}, d_{i, k_i}$(1ci,j,di,j1091 \le c_{i, j}, d_{i, j} \le 10^9),其中 ci,jc_{i, j}di,jd_{i, j} 表示工种编号为 ci,jc_{i, j} 的员工共 di,jd_{i, j} 人加入公司。保证对于所有 1x<yki1 \le x < y \le k_ici,xci,yc_{i, x} \ne c_{i, y}

保证 mim_ikik_i 之和均不超过 10510^5

【输出格式】

输出一行一个整数表示最多能承接几项工程。

【样例解释】

样例解释如下,用 (t,u)(t, u) 表示工种为 tt 的员工有 uu 名。

首先承接没有任何要求的第 55 项工程,承接后工种为 3322 名员工加入公司。公司内现有员工为 {(1,2),(2,1),(3,2)}\{(1, 2), (2, 1), (3, 2)\}

接下来承接第 11 项工程,承接后没有员工加入公司。公司内现有员工仍为 {(1,2),(2,1),(3,2)}\{(1, 2), (2, 1), (3, 2)\}

接下来承接第 22 项工程,承接后工种为 3322 名员工,以及工种为 2211 名员工加入公司。公司内现有员工为 {(1,2),(2,2),(3,4)}\{(1, 2), (2, 2), (3, 4)\}

接下来承接第 44 项工程,承接后工种为 1133 名员工加入公司。公司内现有员工为 {(1,5),(2,2),(3,4)}\{(1, 5), (2, 2), (3, 4)\}

由于工种为 22 的员工不足 33 名,因此无法承接仅剩的第 33 项工程。

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

提示

We explain the sample test case as follows. Let (t,u)(t, u) indicate uu employees whose occupation is tt.

First, undertake the 55-th project with no requirements. After undertaking the project, there are 22 employees, whose occupation is 33, joining the company. The company now have these employees: {(1,2),(2,1),(3,2)}\{(1, 2), (2, 1), (3, 2)\}.

Next, undertake the 11-st project. After undertaking the project, no employee joins the company. The company now still have these employees: {(1,2),(2,1),(3,2)}\{(1, 2), (2, 1), (3, 2)\}.

Next, undertake the 22-nd project. After undertaking the project, there are 22 employees, whose occupation is 33, and 11 employee, whose occupation is 22, joining the company. The company now have these employees: {(1,2),(2,2),(3,4)}\{(1, 2), (2, 2), (3, 4)\}.

Next, undertake the 44-th project. After undertaking the project, there are 33 employees, whose occupation is 11, joining the company. The company now have these employees: {(1,5),(2,2),(3,4)}\{(1, 5), (2, 2), (3, 4)\}.

As the company does not have 33 employees whose occupation is 22, we cannot undertake the 33-rd project.