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):
h, w, m = map(int, input().split())
h_cnt = [0 for i in range(h)]
w_cnt = [0 for i in range(w)]
bomb = set()
for _ in range(m):
    c_h, c_w = map(int, input().split())
    h_cnt[c_h-1] +=1
    w_cnt[c_w-1]+=1
    bomb.add(((c_h-1),(c_w-1)))

max_h = [i for i in range(len(h_cnt)) if h_cnt[i] == max(h_cnt)]
max_w = [i for i in range(len(w_cnt)) if h_cnt[i] == max(w_cnt)]

ans = []
for i in max_h:
    for j in max_w:
        if (i,j) in bomb:
            ans.append(h_cnt[i] + w_cnt[j] -1)
        else:
            ans.append(h_cnt[i] + w_cnt[j])

print(max(ans))

import numpy as np
h, w, m = map(int, input().split())
arr = np.zeros([h,w])

import numpy as np
h, w, m = map(int, input().split())
arr = np.zeros([h, w], dtype=np.int8)
for _ in range(m):
    c_h, c_w = map(int, input().split())
    arr[c_h-1, c_w-1] = 1
    
row_sum = np.sum(arr, axis=1)
col_sum = np.sum(arr, axis=0)
row_max_pos = np.argwhere(row_sum == np.max(row_sum))
col_max_pos = np.argwhere(col_sum == np.max(col_sum))
    
row_max = int(max(row_sum))
col_max = int(max(col_sum))

ans = []
for i in row_max_pos:
    for j in col_max_pos:
        if arr[i,j] == 1:
            ans.append(row_max + col_max-1)
        else
            ans.append(row_max + col_max-1)

h, w, m = map(int, input().split())
h_cnt = [0 for i in range(h)]
w_cnt = [0 for i in range(w)]
bomb = set()
for _ in range(m):
    c_h, c_w = map(int, input().split())
    h_cnt[c_h-1] +=1
    w_cnt[c_w-1]+=1
    bomb.add(((c_h-1),(c_w-1)))
    
h_max = max(h_cnt)
w_max = max(w_cnt)
    
max_h = [i for i in range(h) if h_cnt[i] == h_max]
max_w = [i for i in range(w) if w_cnt[i] == w_max]

flg = 0
for i in max_h:
    for j in max_w:
        if (i,j) not in bomb:
            flg = 1
            break

if flg:
    print(max_h + max_w)
else:
    print(max_h + max_w -1)

import numpy as np
h, w, m = map(int, input().split())
arr = np.zeros([h,w])
for _ in range(m):
    c_h, c_w = map(int, input().split())
    arr[c_h-1, c_w-1] = 1

h, w, m = map(int, input().split())
h_cnt = [0 for i in range(h)]
w_cnt = [0 for i in range(w)]
bomb = set()
for _ in range(m):
    c_h, c_w = map(int, input().split())
    h_cnt[c_h-1] +=1
    w_cnt[c_w-1]+=1
    bomb.add(((c_h-1),(c_w-1)))
    
h_max = max(h_cnt)
w_max = max(w_cnt)
    
max_h = [i for i in range(len(h_cnt)) if h_cnt[i] == h_max]
max_w = [i for i in range(len(w_cnt)) if h_cnt[i] == w_max]

flg = 0
for i in max_h:
    for j in max_w:
        if (i,j) not in bomb:
            flg = 1
            break

if flg:
    print(max_h + max_w)
else:
    print(max_h + max_w -1)

import numpy as np
h, w, m = map(int, input().split())
arr = np.zeros([h, w], dtype=np.int8)
for _ in range(m):
    c_h, c_w = map(int, input().split())
    arr[c_h-1, c_w-1] = 1
    
row_sum = np.sum(arr, axis=1)
col_sum = np.sum(arr, axis=0)
row_max_pos = np.argwhere(row_sum == np.max(row_sum))
col_max_pos = np.argwhere(col_sum == np.max(col_sum))
    
row_max = int(max(row_sum))
col_max = int(max(col_sum))

ans = []
for i in row_max_pos:
    for j in col_max_pos:
        if arr[i,j] == 1:
            ans.append(row_max + col_max-1)
        else:
            ans.append(row_max + col_max-1)

h, w, m = map(int, input().split())
h_cnt = [0 for i in range(h)]
w_cnt = [0 for i in range(w)]
bomb = set()
for _ in range(m):
    c_h, c_w = map(int, input().split())
    h_cnt[c_h-1] +=1
    w_cnt[c_w-1]+=1
    bomb.add(((c_h-1),(c_w-1)))

max_h = [i for i in range(len(h_cnt)) if h_cnt[i] == max(h_cnt)]
max_w = [i for i in range(len(w_cnt)) if h_cnt[i] == max(w_cnt)]

ans = []
for i in max_h:
    for j in max_w
    if (i,j) in bomb:
        ans.append(h_cnt[i] + w_cnt[j] -1)
    else:
        ans.append(h_cnt[i] + w_cnt[j])

print(max(ans))

import numpy as np
h, w, m = map(int, input().split())
arr = np.zeros([h,w])
for _ in range(m):
    c_h, c_w = map(int, input().split())
    arr[c_h-1, c_w-1] = 1
    
row_sum = np.sum(arr, axis=1)
col_sum = np.sum(arr, axis=0)
row_max_pos = np.argwhere(row_sum == np.max(row_sum))
col_max_pos = np.argwhere(col_sum == np.max(col_sum))

import numpy as np
h, w, m = map(int, input().split())
arr = np.zeros([h,w])
for _ in range(m):
    c_h, c_w = map(int, input().split())
    arr[c_h-1, c_w-1] = 1
    
row_sum = np.sum(arr, axis=1)
col_sum = np.sum(arr, axis=0)
row_max_pos = np.argwhere(row_sum == np.max(row_sum))
col_max_pos = np.argwhere(col_sum == np.max(col_sum))
    
row_max = int(max(row_sum))
col_max = int(max(col_sum))
ans = row_max + col_max

import numpy as np
h, w, m = map(int, input().split())

h, w, m = map(int, input().split())
h_cnt = [0 for i in range(h)]
w_cnt = [0 for i in range(w)]
bomb = set()

for i in range(m):
    _h, _w = map(int, input().split())
    h_cnt[_h-1] += 1
    w_cnt[_w-1] += 1
    bomb.add(((_h-1),(_w-1))) 

h_max = max(h_cnt)
w_max = max(w_cnt)

max_h = []
max_w = []

for i in range(h):
    if h_cnt[i] == h_max:
        max_h.append(i)

for i in range(w):
    if w_cnt[i] == w_max:
        max_w.append(i)

flg = True

for i in max_h:
    for j in max_w:
        if (i,j) not in bomb:
            flg = False
            break
print(h_max+w_max-1 if flg else h_max+w_max)


Verdicts: Runtime Error

Runtime Error

Runtime Error

Runtime Error

Runtime Error

Runtime Error

Runtime Error

Runtime Error

Runtime Error

Runtime Error

Wrong Answer

Accepted