#P7637. [BalticOI 2006] BITWISE EXPRESSIONS (Day 1)
[BalticOI 2006] BITWISE EXPRESSIONS (Day 1)
Description
For simplicity, the expression has a specific form: it consists of several subexpressions in parentheses, separated by the bitwise AND operator (denoted by ). Each subexpression consists of one or more variables, separated by the bitwise OR operator (denoted by ). With this convention, the expression can be fully specified by giving the number of subexpressions and the number of variables in each subexpression. Variables are numbered only according to their occurrences in the expression.
For example, if the number of subexpressions is , and the numbers of variables in each subexpression are , , , , then the expression is:
$$E=(v_1|v_2|v_3) \& (v_4) \& (v_5|v_6) \& (v_7|v_8)$$Bitwise operators are defined in the usual way. For example, to compute , we first write the numbers (operands) in binary: and (because and ). Each binary digit of the result now depends on the corresponding digits of the operands: if both operands have , then the result digit is , otherwise it is . As shown on the left in the figure below, the result is . If we want to compute , the process is the same, except that if the corresponding digit is in any operand, then the result is . Therefore, the result digit is only when both operands have . As shown in the middle of the figure below, the result is . Extending this to more than two operands is straightforward. The example on the right below shows that .

Input Format
The first line contains two positive integers and . The second line contains positive integers (), where is the number of variables in the -th subexpression. Each is at least , and their sum equals . The next lines each contain two integers and , specifying the value range of the -th variable in the expression by .
Output Format
One line containing one integer: the maximum value the expression can take.
8 4
3 1 2 2
2 4
1 4
0 0
1 7
1 4
1 2
3 4
2 3
6
Hint
Constraints
For of the testdata, , , .
Sample Explanation
The sample restricts the values of the eight variables in the expression as follows: , , , , , , , and . If written in binary, one of the best assignments gives the expression . From this we can see that all subexpressions can become equal to except the third one.
Problem Notes
From Baltic Olympiad in Informatics 2006 Day 1:Bitwise.
Translated and organized by @求学的企鹅.
Translated by ChatGPT 5
京公网安备 11011102002149号