結果

問題 No.165 四角で囲え!
ユーザー ckawatak
提出日時 2017-09-13 21:47:05
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
WA  
実行時間 -
コード長 1,354 bytes
コンパイル時間 105 ms
コンパイル使用メモリ 12,928 KB
実行使用メモリ 11,008 KB
最終ジャッジ日時 2024-11-07 20:05:11
合計ジャッジ時間 1,878 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2 WA * 2
other AC * 7 WA * 12
権限があれば一括ダウンロードができます

ソースコード

diff #

def lower_ends(points, axis):
    ends = [points[0]]
    for i in range(1, len(points)):
        if points[i][axis] == ends[0][axis]:
            ends.append(points[i])
        else:
            break
    return ends

def upper_ends(points, axis):
    ends = [points[-1]]
    for i in reversed(range(1, len(points)-1)):
        if points[i][axis] == ends[0][axis]:
            ends.append(points[i])
        else:
            break
    return ends

def score(points):
    total = 0
    for p in points:
        total += p[2]
    return total

N,B = list(map(int, input().split(' ')))

total = 0
points = []
for n in range(N):
    x,y,p = list(map(int, input().split(' ')))
    points.append((x,y,p))
    total += p

horizontal = sorted(points, key=lambda point: point[0])
vertical = sorted(points, key=lambda point: point[1])

if total <= B:
    print(N)
    exit()

while B < total:
    bottom = lower_ends(vertical, 1)
    top = upper_ends(vertical, 1)
    left = lower_ends(horizontal, 0)
    right = upper_ends(horizontal, 0)
    
    scores = {
        score(bottom): bottom,
        score(top): top,
        score(left): left,
        score(right): right
        }

    max = sorted(scores.keys())[-1]
    removed = scores[max]
    for r in removed:
        horizontal.remove(r)
        vertical.remove(r)

    total -= max

print(len(horizontal))
0