結果

問題 No.2408 Lakes and Fish
ユーザー bug maker / ばぐめいかー@Python学習者bug maker / ばぐめいかー@Python学習者
提出日時 2023-08-11 21:47:22
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
RE  
実行時間 -
コード長 836 bytes
コンパイル時間 104 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 38,412 KB
最終ジャッジ日時 2024-04-29 12:39:45
合計ジャッジ時間 6,711 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 31 ms
10,624 KB
testcase_01 AC 31 ms
10,624 KB
testcase_02 AC 35 ms
10,752 KB
testcase_03 AC 35 ms
10,624 KB
testcase_04 AC 374 ms
38,012 KB
testcase_05 AC 380 ms
38,160 KB
testcase_06 AC 347 ms
37,828 KB
testcase_07 AC 451 ms
38,284 KB
testcase_08 AC 453 ms
38,412 KB
testcase_09 AC 446 ms
38,220 KB
testcase_10 AC 442 ms
38,284 KB
testcase_11 RE -
testcase_12 AC 338 ms
30,804 KB
testcase_13 AC 130 ms
16,620 KB
testcase_14 RE -
testcase_15 RE -
testcase_16 AC 225 ms
20,248 KB
testcase_17 RE -
testcase_18 AC 283 ms
25,276 KB
testcase_19 RE -
testcase_20 RE -
testcase_21 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = lambda :sys.stdin.readline()[:-1] 

from bisect import bisect_left, bisect, insort_left, insort

def main():
    N, M = map(int, input().split())
    
    L = list(map(int, input().split()))
    
    L.sort()
    
    L = [float("-inf")] + L + [float("inf")]    # 左右に無限大つけることでindex errorを回避
    
    # print(L)
    
    fbw = [list(map(int, input().split())) for _ in range(N)]
    
    sg = 0
    cost = 0
    
    for i in range(M):  # 二分探索使う
        idx = bisect_left(L, fbw[i][0])
        if min(fbw[i][0] - L[idx - 1], L[idx] - fbw[i][0]) < fbw[i][2] - fbw[i][1]:
            sg += fbw[i][2]
            cost += min(fbw[i][0] - L[idx - 1], L[idx] - fbw[i][0])
        else:
            sg += fbw[i][1]

    print(sg - cost)    
    
if __name__ == '__main__':
    main()
0