結果

問題 No.2408 Lakes and Fish
ユーザー ryomac
提出日時 2023-08-11 21:43:20
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 594 bytes
コンパイル時間 616 ms
コンパイル使用メモリ 82,324 KB
実行使用メモリ 168,928 KB
最終ジャッジ日時 2024-11-18 15:44:22
合計ジャッジ時間 44,667 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 6 TLE * 13
権限があれば一括ダウンロードができます

ソースコード

diff #

from bisect import bisect_left, bisect_right

N, M = map(int, input().split())
L = list(map(int, input().split()))
FBW = [list(map(int, input().split())) for _ in range(M)]

ans = 0
for i in range(M):
    f, b, w = FBW[i]
    if f in L:
        ans += w
    else:
        idx = bisect_left(L, f)
        if idx == 0:
            cost = L[0] - f
        elif idx == N:
            cost = f - L[-1]
        else:
            near = L[bisect_left(L, f)]
            near2 = L[bisect_right(L, f) - 1]
            cost = min(abs(f - near), abs(f - near2))
        ans += max(w - cost, b)
print(ans)
0