結果

問題 No.2408 Lakes and Fish
ユーザー かとぅー ☆
提出日時 2023-09-04 21:59:16
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 261 ms / 2,000 ms
コード長 589 bytes
コンパイル時間 421 ms
コンパイル使用メモリ 82,344 KB
実行使用メモリ 107,004 KB
最終ジャッジ日時 2024-06-22 19:26:52
合計ジャッジ時間 5,372 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 19
権限があれば一括ダウンロードができます

ソースコード

diff #

from bisect import bisect_left
from collections import defaultdict

N, M = map(int, input().split())
L = list(map(int, input().split())) 
L.sort()
mi = L[0]
ma = L[-1]
d = defaultdict(int) 
for i in range(N):
    d[L[i]] += 1
ans = 0 
for i in range(M):
    f, b, w = map(int, input().split())  
    if f in d:
        ans += w     
    else:
        if f > ma:
            ans += max(w-abs(f-ma), b)
        elif mi > f:
            ans += max(w-abs(f-mi), b)
        else:
            e = bisect_left(L, f)          
            ans += max(w-abs(L[e]-f), w-abs(L[e-1]-f), b)

print(ans)
0