結果

問題 No.59 鉄道の旅
ユーザー NanamachiNanamachi
提出日時 2017-02-15 10:07:32
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 821 bytes
コンパイル時間 88 ms
コンパイル使用メモリ 10,944 KB
実行使用メモリ 15,008 KB
最終ジャッジ日時 2023-08-28 17:07:58
合計ジャッジ時間 6,970 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 17 ms
15,008 KB
testcase_01 AC 17 ms
7,788 KB
testcase_02 AC 16 ms
7,788 KB
testcase_03 AC 16 ms
7,784 KB
testcase_04 TLE -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#-*- coding: utf-8 -*-
class Train():
    def __init__(self, K):
        self.cargo = []
        self.K = K

    def load(self, weight):
        if len(self.cargo) < self.K:
            self.cargo.append(weight)
            self.cargo.sort()
        elif self.cargo[-self.K] < weight:
            self.cargo.append(weight)
            self.cargo.sort()

        return None

    def unload(self, weight):
        if weight in self.cargo:
            i = self.cargo.index(weight)
            del self.cargo[i]

        return None

def station(ft, W):
    if W > 0:
        ft.load(W)
    else:
        ft.unload(-W)

def main(N, K):
    ft = Train(int(K))
    for i in range(int(N)):
        W = int(input())
        station(ft, W)

    return len(ft.cargo)

if __name__ == '__main__':
    print(main(*(input().split())))
0