Problem p03576 (python)

Fixed submission:

import itertools as it

from functools import *
import sys
sys.setrecursionlimit(100000)
input = sys.stdin.readline


def acinput():
    return list(map(int, input().split(" ")))


def II():
    return int(input())



N, K = acinput()


ary = [acinput() for i in range(N)]
x = list(map(lambda x: x[0], sorted(ary, key=lambda s: s[0])))
y = list(map(lambda x: x[1], sorted(ary, key=lambda x: x[1])))


#print(list(it.combinations(y,2)))
#print(list(x))

res = 10**20
for sy in it.combinations(y, 2):
    #print(sy)
    for sx in it.combinations(x, 2):
        #print(sx)
        #print(sy, sx)
        count = 0
        for sa in ary:
            
            if sy[0] <= sa[1] and sa[1] <= sy[1]:
                if sx[0] <= sa[0] and sa[0] <= sx[1]:
                    count += 1

        #print(count)
        if count >= K:
            #dx = np.diff(sx)[0]
            #dy = np.diff(sy)[0]
            dx=sx[1]-sx[0]
            dy=sy[1]-sy[0]
            #print(dx,dy)
            res = min(res, dx*dy)
            #print(res)

print(res)

Buggy submission (verdict: Runtime Error):

import itertools as it
import numpy as np
from functools import *
import sys
sys.setrecursionlimit(100000)
input = sys.stdin.readline


def acinput():
    return list(map(int, input().split(" ")))


def II():
    return int(input())


directions = np.array([[1, 0], [0, 1], [-1, 0], [0, -1]])
directions = list(map(np.array, directions))

mod = 10**9+7


def factorial(n):
    fact = 1
    for integer in range(1, n + 1):
        fact *= integer
    return fact


def serch(x, count):
    #print("top", x, count)

    for d in directions:
        nx = d+x
        # print(nx)
        if np.all(0 <= nx) and np.all(nx < (H, W)):
            if field[nx[0]][nx[1]] == "E":
                count += 1
                field[nx[0]][nx[1]] = "V"
                count = serch(nx, count)
                continue
            if field[nx[0]][nx[1]] == "#":
                field[nx[0]][nx[1]] = "V"
                count = serch(nx, count)

    return count


N, K = acinput()


ary = [acinput() for i in range(N)]
x = list(map(lambda x: x[0], sorted(ary, key=lambda s: s[0])))
y = list(map(lambda x: x[1], sorted(ary, key=lambda x: x[1])))


#print(list(it.combinations(y,2)))
#print(list(x))

res = 10**20
for sy in it.combinations(y, 2):
    #print(sy)
    for sx in it.combinations(x, 2):
        #print(sx)
        #print(sy, sx)
        count = 0
        for sa in ary:
            
            if sy[0] <= sa[1] and sa[1] <= sy[1]:
                if sx[0] <= sa[0] and sa[0] <= sx[1]:
                    count += 1

        #print(count)
        if count >= K:
            dx = np.diff(sx)[0]
            dy = np.diff(sy)[0]
            #print(dx,dy)
            res = min(res, dx*dy)
            #print(res)

print(res)

Buggy submission (verdict: Runtime Error):

def menseki(S):
    sx=[ss[0] for ss in S]
    sy=[ss[1] for ss in S]

    zahyominmax=[min(sx),max(sx),min(sy),max(sy)]
    return (zahyominmax[1]-zahyominmax[0])*(zahyominmax[3]-zahyominmax[2])



def spaceinput():
    return list(map(int,input().split(" ")))



N,K=spaceinput()

x=[]
for i in range(N):
    x.append(spaceinput())

x=sorted(x,key=lambda s:s[0])

S=x[:K]

sx=[ss[0] for ss in S]
sy=[ss[1] for ss in S]

zahyominmax=[min(sx),max(sx),min(sy),max(sy)]
minmenseki=(zahyominmax[1]-zahyominmax[0])*(zahyominmax[3]-zahyominmax[2])


for i in range(K,len(x)):

    #print(S)
    a=x[i]
    S.append(a)

    #minmenseki=menseki
    for k in range(len(S)):
        bb=S[:k]
        bb.extend(S[k+1:])
        s=menseki(bb)
        if s<minmenseki:
            minmenseki=s
            kmin=k


    #menseki=minmenseki
    del S[kmin]


print(minmenseki)

Buggy submission (verdict: Runtime Error):
N,K=spaceinput()

x=[]
for i in range(N):
    x.append(spaceinput())

x=sorted(x,key=lambda s:s[0])

S=x[:K]

sx=[ss[0] for ss in S]
sy=[ss[1] for ss in S]

zahyominmax=[min(sx),max(sx),min(sy),max(sy)]
menseki=(zahyominmax[1]-zahyominmax[0])*(zahyominmax[3]-zahyominmax[2])


for i in range(K,len(x)):
    a=x[i]
    nzahyominmax=zahyominmax[:]
    nzahyominmax[1]=a[0]

    if nzahyominmax[2]>a[1]:
        nzahyominmax[2]=a[1]

    if nzahyominmax[3]<a[1]:
        nzahyominmax[3]=a[1]


    news=(zahyominmax[1]-zahyominmax[0])*(zahyominmax[3]-zahyominmax[2])

    if menseki>news:
        menseki=news


print(menseki)

Buggy submission (verdict: Runtime Error):
N,K=spaceinput()

x=[]
for i in range(N):
    x.append(spaceinput())

x=sorted(x,key=lambda s:s[0])

S=x[:K]

sx=[ss[0] for ss in S]
sy=[ss[1] for ss in S]

zahyominmax=[min(sx),max(sx),min(sy),max(sy)]
menseki=(zahyominmax[1]-zahyominmax[0])*(zahyominmax[3]-zahyominmax[2])


for i in range(K,len(x)):
    a=x[i]
    nzahyominmax=zahyominmax[:]
    nzahyominmax[1]=a[0]

    if nzahyominmax[2]>a[1]:
        nzahyominmax[2]=a[1]

    if nzahyominmax[3]<a[1]:
        nzahyominmax[3]=a[1]


    news=(zahyominmax[1]-zahyominmax[0])*(zahyominmax[3]-zahyominmax[2])

    if menseki>news:
        menseki=news


print(menseki)