Problem p02926 (python)

Fixed submission:
N = int(input())
points = []
for i in range(N):
    x, y = map(int, input().split())
    if (x, y) == (0, 0): N -= 1; continue
    points.append((x,y))

if not points:
    print(0)
    quit()
    
PI = 3.14

import math
points.sort(key=lambda x : math.atan2(x[0], x[1]))

def calc(points):
    # Greedy optimality
    l = 0
    h = 1

    xsum = points[0][0]
    ysum = points[0][1]

    highest = xsum ** 2 + ysum ** 2
    while h < len(points):
        nx, ny = xsum - points[l][0], ysum - points[l][1]
        if (not l >= h) and nx ** 2 + ny ** 2 > xsum ** 2 + ysum ** 2 or h - l >= N:
            xsum, ysum = nx, ny
            l += 1
        else:
            xsum += points[h][0]
            ysum += points[h][1]
            h += 1
        highest = max(highest, xsum ** 2 + ysum ** 2)
    return highest

def calc2(points):
    hi = 0
    
    for s in range(N):
        for j in range(1,N+1):
            xt = yt = 0
            for x in range(j):
                xt += points[s+x][0]
                yt += points[s+x][1]
            hi = max(hi, xt ** 2 + yt ** 2)

    return hi ** 0.5

print(calc2(points + points))

Buggy submission (verdict: Runtime Error):
N = int(input())
points = []
for i in range(N):
    x, y = map(int, input().split())
    if (x, y) == (0, 0): continue
    points.append((x,y))

if not points:
    print(0)
    quit()
    
PI = 3.14

import math
points.sort(key=lambda x : math.atan2(x[0], x[1]))

def calc(points):
    # Greedy optimality
    l = 0
    h = 1

    xsum = points[0][0]
    ysum = points[0][1]

    highest = xsum ** 2 + ysum ** 2
    while h < len(points):
        nx, ny = xsum - points[l][0], ysum - points[l][1]
        if (not l >= h) and nx ** 2 + ny ** 2 > xsum ** 2 + ysum ** 2 or h - l >= N:
            xsum, ysum = nx, ny
            l += 1
        else:
            xsum += points[h][0]
            ysum += points[h][1]
            h += 1
        highest = max(highest, xsum ** 2 + ysum ** 2)
    return highest

def calc2(points):
    # Dot product
    hi = 0
    
    for s in range(N):
        for j in range(1,N+1):
            xt = yt = 0
            for x in range(j):
                xt += points[s+x][0]
                yt += points[s+x][1]
            hi = max(hi, xt ** 2 + yt ** 2)

    return hi ** 0.5

print(calc2(points + points))

Buggy submission (verdict: Runtime Error):
N = int(input())
points = []
for i in range(N):
    x, y = map(int, input().split())
    if (x, y) == (0, 0): continue
    points.append((x,y))

PI = 3.14

import math
points.sort(key=lambda x : math.atan2(x[0], x[1]))

def calc(points):
    l = 0
    h = 1

    xsum = points[0][0]
    ysum = points[0][1]

    highest = xsum ** 2 + ysum ** 2
    while h < len(points):
        nx, ny = xsum - points[l][0], ysum - points[l][1]
        if (not l >= h) and nx ** 2 + ny ** 2 > xsum ** 2 + ysum ** 2 or h - l >= N:
            xsum, ysum = nx, ny
            l += 1
        else:
            xsum += points[h][0]
            ysum += points[h][1]
            h += 1
        highest = max(highest, xsum ** 2 + ysum ** 2)
    return highest

print(calc(points + points) ** 0.5)

Buggy submission (verdict: Runtime Error):
N = int(input())
points = []
for i in range(N):
    x, y = map(int, input().split())
    points.append((x,y))

PI = 3.14

import math
points.sort(key=lambda x : math.atan2(x[0], x[1]))

def calc(points):
    l = 0
    h = 1

    xsum = points[0][0]
    ysum = points[0][1]

    highest = xsum ** 2 + ysum ** 2
    while h < 2*N:
        nx, ny = xsum - points[l][0], ysum - points[l][1]
        if (not l >= h) and nx ** 2 + ny ** 2 > xsum ** 2 + ysum ** 2 or h - l >= N:
            xsum, ysum = nx, ny
            l += 1
        else:
            xsum += points[h][0]
            ysum += points[h][1]
            h += 1
        highest = max(highest, xsum ** 2 + ysum ** 2)
    return highest

if calc(points) > calc(points + points): print(1/0)
print(max(calc(points), calc(points + points)) ** 0.5)

Buggy submission (verdict: Runtime Error):
N = int(input())
points = []
for i in range(N):
    x, y = map(int, input().split())
    points.append((x,y))

import math
points.sort(key=lambda x : math.atan2(x[0], x[1]))

def calc(points):
    l = 0
    h = 1

    xsum = points[0][0]
    ysum = points[0][1]

    highest = xsum ** 2 + ysum ** 2
    while h < N:
        nx, ny = xsum - points[l][0], ysum - points[l][1]
        if nx ** 2 + ny ** 2 > xsum ** 2 + ysum ** 2:
            xsum, ysum = nx, ny
            l += 1
        else:
            xsum += points[h][0]
            ysum += points[h][1]
            h += 1
        highest = max(highest, xsum ** 2 + ysum ** 2)
    return max(highest, nx ** 2 + ny ** 2)

print(max(calc(points), calc(points[N//2:] + points[:N//2])) ** 0.5)