Problem: We have a two-dimensional grid with H \times W squares. There are M targets to destroy in this grid - the position of the i-th target is \left(h_i, w_i \right).  Takahashi will choose one square in this grid, place a bomb there, and ignite it. The bomb will destroy all targets that are in the row or the column where the bomb is placed. It is possible to place the bomb at a square with a target.  Takahashi is trying to maximize the number of targets to destroy. Find the maximum number of targets that can be destroyed.

Submission attempts (in order):
import numpy as np

[H, W, M] = map(int, input().split())
mp = np.zeros((2+1, 2+1), dtype=np.int64)

#    [h, w] = map(int, input().split())
#    mp[h][w] = 1




#maxcol = max(colsum)
#maxrow = max(rowsum)

#colchk = np.where(colsum==maxcol)
#rowchk = np.where(rowsum==maxrow)


#    for j in range(len(colchk[0])):
#        if mp[rowchk[0][i]][colchk[0][j]] == 0:
#            print(int(max(colsum)+max(rowsum)))


#print(int(max(colsum)+max(rowsum))-1)


import numpy as np

[H, W, M] = map(int, input().split())
mp = np.zeros((H+1, W+1), dtype=np.int64)

#    [h, w] = map(int, input().split())
#    mp[h][w] = 1

colsum = np.sum(mp, axis=0)
rowsum = np.sum(mp, axis=1)

#maxcol = max(colsum)
#maxrow = max(rowsum)

#colchk = np.where(colsum==maxcol)
#rowchk = np.where(rowsum==maxrow)


#    for j in range(len(colchk[0])):
#        if mp[rowchk[0][i]][colchk[0][j]] == 0:
#            print(int(max(colsum)+max(rowsum)))


print(int(max(colsum)+max(rowsum))-1)


import numpy as np

[H, W, M] = map(int, input().split())
mp = np.zeros((H+1, W+1), dtype=np.int64)
for i in range(M):
    [h, w] = map(int, input().split())
    mp[h][w] = 1

colsum = np.sum(mp, axis=0)
rowsum = np.sum(mp, axis=1)

maxcol = max(colsum)
maxrow = max(rowsum)

#colchk = np.where(colsum==maxcol)
#rowchk = np.where(rowsum==maxrow)


#    for j in range(len(colchk[0])):
#        if mp[rowchk[0][i]][colchk[0][j]] == 0:
#            print(int(max(colsum)+max(rowsum)))


print(int(max(colsum)+max(rowsum))-1)



import numpy as np

[H, W, M] = map(int, input().split())
mp = np.zeros((H+1, W+1), dtype=np.int64)
for i in range(M):
    [h, w] = map(int, input().split())
    mp[h][w] = 1

colsum = np.sum(mp, axis=0)
rowsum = np.sum(mp, axis=1)

maxcol = max(colsum)
maxrow = max(rowsum)

colchk = np.where(colsum==maxcol)
rowchk = np.where(rowsum==maxrow)


#    for j in range(len(colchk[0])):
#        if mp[rowchk[0][i]][colchk[0][j]] == 0:
#            print(int(max(colsum)+max(rowsum)))


print(int(max(colsum)+max(rowsum))-1)


import numpy as np

[H, W, M] = map(int, input().split())
mp = np.zeros((H+1, W+1), dtype=np.int64)
for i in range(M):
    [h, w] = map(int, input().split())
    mp[h][w] = 1

colsum = np.sum(mp, axis=0)
rowsum = np.sum(mp, axis=1)

#maxcol = max(colsum)
#maxrow = max(rowsum)

#colchk = np.where(colsum==maxcol)
#rowchk = np.where(rowsum==maxrow)


#    for j in range(len(colchk[0])):
#        if mp[rowchk[0][i]][colchk[0][j]] == 0:
#            print(int(max(colsum)+max(rowsum)))


print(int(max(colsum)+max(rowsum))-1)


import numpy as np

[H, W, M] = map(int, input().split())
mp = np.zeros((H+1, W+1), dtype=np.int64)
for i in range(M):
    [h, w] = map(int, input().split())
    mp[h][w] = 1




#maxcol = max(colsum)
#maxrow = max(rowsum)

#colchk = np.where(colsum==maxcol)
#rowchk = np.where(rowsum==maxrow)


#    for j in range(len(colchk[0])):
#        if mp[rowchk[0][i]][colchk[0][j]] == 0:
#            print(int(max(colsum)+max(rowsum)))


print(int(max(colsum)+max(rowsum))-1)


import numpy as np

[H, W, M] = map(int, input().split())
mp = np.zeros((H+1, W+1), dtype=np.int64)

#    [h, w] = map(int, input().split())
#    mp[h][w] = 1




#maxcol = max(colsum)
#maxrow = max(rowsum)

#colchk = np.where(colsum==maxcol)
#rowchk = np.where(rowsum==maxrow)


#    for j in range(len(colchk[0])):
#        if mp[rowchk[0][i]][colchk[0][j]] == 0:
#            print(int(max(colsum)+max(rowsum)))


#print(int(max(colsum)+max(rowsum))-1)


import numpy as np

[H, W, M] = map(int, input().split())
colsum = np.zeros(W+1)
rowsum = np.zeros(H+1)
bombs = []
rowbombs = [set() for i in range(H+1)]
for i in range(M):
    [h, w] = map(int, input().split())
    rowsum[h] += 1
    colsum[w] += 1
    bombs.append([h, w])
    rowbombs[h].add(w)

maxcol = max(colsum)
maxrow = max(rowsum)

colchk = np.where(colsum==maxcol)
rowchk = np.where(rowsum==maxrow)

for i in range(len(rowchk[0])):
    for j in range(len(colchk[0])):
        if colchk[0][j] not in rowbombs[rowchk[0][i]]:
            print(int(max(colsum)+max(rowsum)))
            quit()

print(int(max(colsum)+max(rowsum))-1)


Verdicts: Wrong Answer

Runtime Error

Runtime Error

Runtime Error

Runtime Error

Runtime Error

Runtime Error

Accepted