P4311 Soldiers Occupy

Description

There is an $M \times N$ board, and some cells are obstacles. You need to choose some cells to place soldiers. At most one soldier can be placed in a cell, and soldiers cannot be placed in obstacle cells. We say the soldiers occupy the entire board if, for each row $i$, at least $L_i$ soldiers are placed, and for each column $j$, at least $C_j$ soldiers are placed. Your task is to use the fewest number of soldiers to occupy the entire board.

Input Format

The first line contains three integers $M, N, K$, representing the number of rows, the number of columns, and the number of obstacles. The second line contains $M$ integers representing $L_i$. The third line contains $N$ integers representing $C_j$. The next $K$ lines each contain two integers $X, Y$, indicating that cell $(X, Y)$ is an obstacle.

Output Format

Output one integer representing the minimum number of soldiers required. If it is impossible to occupy the entire board no matter how many soldiers are placed, output `JIONG!`.

Explanation/Hint

For $100\%$ of the testdata, $1 \le M, N \le 100$, $0 \le K \le M \times N$. Translated by ChatGPT 5