#P4311. 士兵占领

士兵占领

Description

There is an M×NM \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 ii, at least LiL_i soldiers are placed, and for each column jj, at least CjC_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,KM, N, K, representing the number of rows, the number of columns, and the number of obstacles.
The second line contains MM integers representing LiL_i.
The third line contains NN integers representing CjC_j.
The next KK lines each contain two integers X,YX, Y, indicating that cell (X,Y)(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!.

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

4

Hint

For 100%100\% of the testdata, 1M,N1001 \le M, N \le 100, 0KM×N0 \le K \le M \times N.

Translated by ChatGPT 5