Problem p03576 (python)

Fixed submission:
n,k=map(int,input().split())
xy=[list(map(int,input().split())) for _ in range(n)]
x=[xy[i][0] for i in range(n)]
y=[xy[i][1] for i in range(n)]
res = 10**20
for i in range(n):
    xl = xy[i][0]
    for j in range(n):
        xr = xy[j][0]
        if xr<xl:continue
        for p in range(n):
            yl = xy[p][1]
            for q in range(n):
                yr = xy[q][1]
                if yr<yl:continue
                tres = 0
                for sxy in xy:
                    if sxy[0] >= xl and sxy[0] <= xr and sxy[1] >= yl and sxy[1] <= yr:
                        tres += 1
                if tres >= k:
                    res = min(res,(xr-xl)*(yr-yl))
print(res)

Buggy submission (verdict: Runtime Error):
n,k=map(int,input().split())
xy=[list(map(int,input().split())) for _ in range(n)]
x=[xy[i][0] for i in range(n)]
y=[xy[i][1] for i in range(n)]

for i in range(n-k):
    x=[xy[i][0] for i in range(n-i)]
    y=[xy[i][1] for i in range(n-i)]
    xl = min(x)
    xr = max(x)
    yl = min(y)
    yr = max(y)

    xr2 = sorted(x)[-2]
    xl2 = sorted(x)[1]
    yr2 = sorted(y)[-2]
    yl2 = sorted(y)[1]

    res1 = (xl2-xl)*(yr-yl)
    res2 = (xr-xr2)*(yr-yl)
    res3 = (yl2-yl)*(xr-xl)
    res4 = (yr-yr2)*(xr-xl)
    if max(res1,res2,res3,res4) ==res1:
        xy.pop(x.index(xl))
    elif max(res1,res2,res3,res4) ==res2:
        xy.pop(x.index(xr))
    elif max(res1,res2,res3,res4) ==res3:
        xy.pop(x.index(yl))
    elif max(res1,res2,res3,res4) ==res4:
        xy.pop(x.index(yr))

x=[xy[i][0] for i in range(k)]
y=[xy[i][1] for i in range(k)]
xl = min(x)
xr = max(x)
yl = min(y)
yr = max(y)
print((xr-xl)*(yr-yl))

Buggy submission (verdict: Runtime Error):
n,k=map(int,input().split())
xy=[list(map(int,input().split())) for _ in range(n)]
x=[xy[i][0] for i in range(n)]
y=[xy[i][1] for i in range(n)]

for i in range(n-k):
    x=[xy[i][0] for i in range(n-i)]
    y=[xy[i][1] for i in range(n-i)]
    xl = min(x)
    xr = max(x)
    yl = min(y)
    yr = max(y)

    xr2 = sorted(x)[-2]
    xl2 = sorted(x)[1]
    yr2 = sorted(y)[-2]
    yl2 = sorted(y)[1]

    res1 = (xl2-xl)*(yr-yl)
    res2 = (xr-xr2)*(yr-yl)
    res3 = (yl2-yl)*(xr-xl)
    res4 = (yr-yr2)*(xr-xl)
    if max(res1,res2,res3,res4) ==res1:
        xy.pop(x.index(xl))
    elif max(res1,res2,res3,res4) ==res2:
        xy.pop(x.index(xr))
    elif max(res1,res2,res3,res4) ==res3:
        xy.pop(x.index(yl))
    elif max(res1,res2,res3,res4) ==res4:
        xy.pop(x.index(yr))

x=[xy[i][0] for i in range(k)]
y=[xy[i][1] for i in range(k)]
xl = min(x)
xr = max(x)
yl = min(y)
yr = max(y)
print((xr-xl)*(yr-yl))

Buggy submission (verdict: Runtime Error):
n,k=map(int,input().split())
xy=[list(map(int,input().split())) for _ in range(n)]
x=[xy[i][0] for i in range(n)]
y=[xy[i][1] for i in range(n)]

for i in range(n-k):
    x=[xy[i][0] for i in range(n-i)]
    y=[xy[i][1] for i in range(n-i)]
    xl = min(x)
    xr = max(x)
    yl = min(y)
    yr = max(y)

    xr2 = sorted(x)[-2]
    xl2 = sorted(x)[0]
    yr2 = sorted(y)[-2]
    yl2 = sorted(y)[0]

    res1 = (xl2-xl)*(yr-yl)
    res2 = (xr-xr2)*(yr-yl)
    res3 = (yl2-yl)*(xr-xl)
    res4 = (yr-yr2)*(xr-xl)
    if max(res1,res2,res3,res4) ==res1:
        xy.pop(x.index(xl))
    elif max(res1,res2,res3,res4) ==res2:
        xy.pop(x.index(xr))
    elif max(res1,res2,res3,res4) ==res3:
        xy.pop(x.index(yl))
    elif max(res1,res2,res3,res4) ==res4:
        xy.pop(x.index(yr))

x=[xy[i][0] for i in range(k)]
y=[xy[i][1] for i in range(k)]
xl = min(x)
xr = max(x)
yl = min(y)
yr = max(y)
print((xr-xl)*(yr-yl))