Problem:


Get Many Persimmon Trees

Seiji Hayashi had been a professor of the Nisshinkan Samurai School
in the domain of Aizu for a long time in the 18th century.
In order to reward him for his meritorious career in education,
Katanobu Matsudaira, the lord of the domain of Aizu, had decided to
grant him a rectangular estate within a large field in the Aizu Basin.
Although the size (width and height) of the estate was strictly specified
by the lord, he was allowed to choose any location for the estate
in the field.
Inside the field which had also a rectangular shape,
many Japanese persimmon trees,
whose fruit was one of the famous products of the Aizu region
known as 'Mishirazu Persimmon', were planted.
Since persimmon was Hayashi's favorite fruit, he wanted to have
as many persimmon trees as possible in the estate given by the lord.

For example, in Figure 1, the entire field is a rectangular grid whose
width and height are 10 and 8 respectively.  Each asterisk (*)
represents a place of a persimmon tree.  If the specified width and
height of the estate are 4 and 3 respectively, the area surrounded by
the solid line contains the most persimmon trees.  Similarly, if the
estate's width is 6 and its height is 4, the area surrounded by the
dashed line has the most, and if the estate's width and height are 3
and 4 respectively, the area surrounded by the dotted line contains
the most persimmon trees.  Note that the width and height cannot be
swapped; the sizes 4 by 3 and 3 by 4 are different, as shown in Figure
1.

  

  Figure 1: Examples of Rectangular Estates

Your task is to find the estate of a given size (width and height)
that contains the largest number of persimmon trees.

Input

The input consists of multiple data sets.
Each data set is given in the following format.

N

W H

x1 y1

x2 y2

...

xN yN

S T

N is the number of persimmon trees,
which is a positive integer less than 500.
W and H are the width and the height of the entire field
respectively.
You can assume that both W and H are positive integers
whose values are less than 100.
For each i (1 <= i <= N), 
xi and yi are
coordinates of the i-th persimmon tree in the grid.
Note that the origin of each coordinate is 1.
You can assume that 1 <= xi <= W
and 1 <= yi <= H,
and no two trees have the same positions.
But you should not assume that the persimmon trees are sorted in some order
according to their positions.
Lastly, S and T are positive integers of
the width and height respectively of the estate given by the lord.
You can also assume that 1 <= S <= W
and 1 <= T <= H.

The end of the input is indicated by a line that solely contains a zero.

Output

For each data set, you are requested to print one line containing the
maximum possible number of persimmon trees that can be included in an
estate of the given size.

Sample Input

16
10 8
2 2
2 5
2 7
3 3
3 8
4 2
4 5
4 8
6 4
6 7
7 5
7 8
8 1
8 4
9 6
10 3
4 3
8
6 4
1 2
2 1
2 4
3 4
4 2
5 3
6 1
6 2
3 2
0

Output for the Sample Input

4
3



Sample input:
16
10 8
2 2
2 5
2 7
3 3
3 8
4 2
4 5
4 8
6 4
6 7
7 5
7 8
8 1
8 4
9 6
10 3
4 3
8
6 4
1 2
2 1
2 4
3 4
4 2
5 3
6 1
6 2
3 2
0


Sample output:
4
3

Submission status: Accepted

Solution code:
def main(n):
    w, h = map(int, input().split())
    xy = [list(map(lambda x:int(x)-1, input().split())) for i in range(n)]
    s, t = map(int, input().split())
    field = [[0] * w for i in range(h)]
    for x, y in xy:
        field[y][x] = 1
    ans = 0
    for y in range(h - t + 1):
        for x in range(w - s + 1):
            b = 0
            for yi in range(t):
                for xi in range(s):
                    b += field[y + yi][x + xi]
            ans = max(ans, b)
    print(ans)
while 1:
    n = int(input())
    if n == 0:
        break
    main(n)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
#AOJ B
from collections import deque

while 1:
    N = int(input())
    if N == 0:
        break
    W,H = map(int,input().split())
    P = [list(map(int,input().split())) for _ in range(N)]
    S,T = map(int,input().split())
    M = [[0 for _ in range(W)] for _ in range(H)]
    for i in P:
        M[i[1]-1][i[0]-1] = 1
    count = [[0 for _ in range(W - S + 1)] for _ in range(H - T + 1)]
    for i in range(H-T+1):
        for j in range(W-S+1):
            for k in range(T):
                for l in range(S):
                    if M[i+k][j+l] == 1:
                        count[i][j] += 1
    m = 0
    for i in range(H - T + 1):
        s = max(count[i])
        if s > m:
            m = s
    print(m)

Submission status: Accepted

Solution code:
while True:
  N = int(input())
  if N==0:
    break
  W,H = map(int,input().split())
  data = [[0 for i in range(W)] for j in range(H)]
  for i in range(N):
    x,y = map(int,input().split())
    data[y-1][x-1] = 1
  S,T = map(int,input().split())
  ans = 0
  for h in range(H-T+1):
    for w in range(W-S+1):
      #
      a = 0
      for x in range(T):
        for y in range(S):
          if data[h+x][w+y]==1:
            a+=1
      ans = max(ans,a)
  print(ans)

Submission status: Runtime Error

Solution code:
trial = int(input())
while True:
    area = [int(n) for n in input().split(" ")]
    trees = []
    for t in range(trial):
        trees.append(int(n) for n in input().split(" "))
    cnt,answer = 0,0
    trees = sorted(trees,key=lambda x:(x[0],x[1]))
    building = [int(n) for n in input().split(" ")]
    for x in range(1,1+area[0]-building[0]):
        for y in range(1,1+area[1]-building[1]):
            cnt = 0
            for tree in trees:
                if x <= tree[0] <= x+building[0] and y <= tree[1] <= y+building[1]:
                    cnt += 1
                elif x+building[0] < tree[0] and y+building[1] < tree[1]:
                    if answer < cnt:
                        answer = cnt    
                        break
            else:
                if answer < cnt:
                    answer = cnt
    else:
        print(answer)
        trial = int(input())
        if trial == 0:
            break

Submission status: Runtime Error

Solution code:
with open("input1(1).txt") as files:
    trial = int(files.readline())
    while True:
        area = [int(n) for n in files.readline().split(" ")]
        trees = []
        for t in range(trial):
            trees.append([int(n) for n in files.readline().split(" ")])
        cnt,answer = 0,0
        trees = sorted(trees,key=lambda x:(x[0],x[1]))
        building = [int(n) for n in files.readline().split(" ")]
        for x in range(1,area[0]-building[0]+2):
            for y in range(1,area[1]-building[1]+2):
                cnt = 0
                for tree in trees:
                    if x <= tree[0] < x+building[0] and y <= tree[1] < y+building[1]:
                        #print(tree,x,y)
                        cnt += 1
                    elif x+building[0] < tree[0] and y+building[1] < tree[1]:
                        if answer < cnt:
                            answer = cnt
                            break
                else:
                    print("")
                    if answer < cnt:
                        answer = cnt
        else:
            print(answer)
            trial = int(files.readline())
            if trial == 0:
                break

Submission status: Runtime Error

Solution code:
while True:
    N = int(input())
    if N == 0: break
    W,H = map(int,input().split())
    fld = [[0 for w in range(W)] for h in range(H)]
    for i in range(N):
        x,y = map(lambda s:int(s)-1,raw_input().split())
        fld[y][x] = 1
    cums = [[0 for w in range(W+1)] for h in range(H+1)]
    for y in range(H):
        for x in range(W):
            cums[y+1][x+1] = fld[y][x] + cums[y][x+1] + cums[y+1][x] - cums[y][x]
    S,T = map(int,input().split())
    ans = 0
    for y in range(H-T+1):
        for x in range(W-S+1):
            ans = max(ans, cums[y+T][x+S] - cums[y+T][x] - cums[y][x+S] + cums[y][x])
    print(ans)