結果

問題 No.2408 Lakes and Fish
ユーザー bug maker / ばぐめいかー@Python学習者bug maker / ばぐめいかー@Python学習者
提出日時 2023-08-11 21:58:17
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 450 ms / 2,000 ms
コード長 844 bytes
コンパイル時間 110 ms
コンパイル使用メモリ 12,544 KB
実行使用メモリ 38,400 KB
最終ジャッジ日時 2024-04-29 12:54:18
合計ジャッジ時間 7,417 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 32 ms
10,752 KB
testcase_01 AC 32 ms
10,624 KB
testcase_02 AC 32 ms
10,624 KB
testcase_03 AC 33 ms
10,624 KB
testcase_04 AC 374 ms
38,084 KB
testcase_05 AC 374 ms
38,192 KB
testcase_06 AC 345 ms
37,868 KB
testcase_07 AC 437 ms
38,272 KB
testcase_08 AC 437 ms
38,400 KB
testcase_09 AC 450 ms
38,212 KB
testcase_10 AC 435 ms
38,212 KB
testcase_11 AC 237 ms
25,384 KB
testcase_12 AC 297 ms
30,408 KB
testcase_13 AC 98 ms
15,844 KB
testcase_14 AC 193 ms
22,188 KB
testcase_15 AC 362 ms
33,068 KB
testcase_16 AC 123 ms
17,924 KB
testcase_17 AC 117 ms
17,024 KB
testcase_18 AC 207 ms
23,728 KB
testcase_19 AC 338 ms
32,196 KB
testcase_20 AC 368 ms
33,664 KB
testcase_21 AC 349 ms
34,004 KB
権限があれば一括ダウンロードができます

ソースコード

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 = [float("-inf")] + L + [float("inf")]    # 左右に無限大つけることでindex errorを回避
    
    # print(L)
    
    fbw = [list(map(int, input().split())) for _ in range(M)]
    
    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)

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