#P9557. Building Company Expansion
Building Company Expansion
Building Company Expansion
You are the boss of a building company. Initially, there are $g$ types of employees in your company. For the $i$-th type, the occupation is denoted by $t_i$ and there are $u_i$ employees in total.
There are $n$ building projects available. To undertake the $i$-th project, your company must satisfy $m_i$ requirements. The $j$-th requirement demands that you have at least $b_{i,j}$ employees whose occupation is $a_{i,j}$. After completing the project, your company gains fame and attracts additional talent: specifically, $k_i$ new groups of employees join where the $j$-th group is of occupation $c_{i,j}$ and consists of $d_{i,j}$ employees.
You may perform any number of projects in any order, with each project undertaken at most once. Note that employees are not consumed by the projects; they remain in your company after its completion. Determine the maximum number of projects you can undertake.
inputFormat
The first line contains two integers $g$ and $n$, representing the number of employee types and the number of projects respectively.
The next $g$ lines each contain two integers $t_i$ and $u_i$, where $t_i$ represents an occupation type and $u_i$ is the count of employees initially of that occupation.
Then, for each project $i$ (from 1 to $n$):
- The first line contains an integer $m_i$, the number of requirements.
- The next $m_i$ lines each contain two integers $a_{i,j}$ and $b_{i,j}$, meaning that at least $b_{i,j}$ employees of occupation $a_{i,j}$ are needed.
- The following line contains an integer $k_i$, the number of employee groups added after completion.
- The next $k_i$ lines each contain two integers $c_{i,j}$ and $d_{i,j}$, indicating that $d_{i,j}$ employees of occupation $c_{i,j}$ will join the company.
outputFormat
Output one integer: the maximum number of projects that can be undertaken.
sample
2 3
1 10
2 5
1
1 5
1
2 3
1
2 8
1
2 1
1
1 1
2
1 10
2 5
2
1 2
2 2
3