#P3325. Voltage Stabilization Components Installation
Voltage Stabilization Components Installation
Voltage Stabilization Components Installation
A renowned chip company requires you to install voltage stabilizing components on their latest products. Each chip is designed as an square board with slots. Some slots are unavailable (represented by '/'), and some are already occupied by components (represented by 'C'). The remaining available slots (represented by '.') can be used to add new components.
However, for electrical stability you must satisfy the following constraints:
1. For each row , you are given a non-negative integer and column indices . It must hold that
[
R_i \leq C_{r_{i,1}} + C_{r_{i,2}} + \cdots + C_{r_{i,T_i}},
]
where is the total number of components in row (including pre-occupied slots) and is the total number of components in column .
2. For each row , a floating-point number () is given. The number of components in row must not exceed times the total components on the chip, i.e.,
[
R_i \leq s_i \cdot X,
]
where is the total number of components on the chip.
3. For each column , a floating-point number () is provided. The number of components in column must not exceed times the total components, i.e.,
[
C_j \leq t_j \cdot X.
]
Your task is to insert as many additional components as possible into available slots, while obeying all the above constraints. Note that the already occupied slots are counted in the totals.
inputFormat
The first line contains an integer , denoting the size of the chip (the chip is an board).
The next lines each contain a string of length , consisting of characters '.', '/', and 'C', representing available slots, unavailable slots, and pre-occupied slots, respectively.
Then follow lines, one per row (1-indexed). Each such line begins with an integer , followed by integers (the column indices ) and a floating point number .
The last line contains floating point numbers, representing .
outputFormat
Output a single integer: the maximum number of additional components that can be inserted while satisfying all given constraints.
sample
3
.C.
/..
...
1 2 0.5
0 1.0
2 1 3 0.7
0.6 0.8 1.0
1
</p>