結果

問題 No.2408 Lakes and Fish
ユーザー ryomacryomac
提出日時 2023-08-11 21:45:02
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 368 ms / 2,000 ms
コード長 672 bytes
コンパイル時間 178 ms
コンパイル使用メモリ 82,176 KB
実行使用メモリ 91,520 KB
最終ジャッジ日時 2024-04-29 12:36:53
合計ジャッジ時間 6,446 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 42 ms
52,608 KB
testcase_01 AC 41 ms
51,840 KB
testcase_02 AC 41 ms
52,224 KB
testcase_03 AC 41 ms
51,712 KB
testcase_04 AC 273 ms
90,752 KB
testcase_05 AC 265 ms
90,908 KB
testcase_06 AC 231 ms
90,624 KB
testcase_07 AC 357 ms
91,432 KB
testcase_08 AC 367 ms
91,008 KB
testcase_09 AC 357 ms
91,424 KB
testcase_10 AC 368 ms
91,520 KB
testcase_11 AC 246 ms
83,584 KB
testcase_12 AC 288 ms
88,320 KB
testcase_13 AC 156 ms
79,488 KB
testcase_14 AC 215 ms
81,920 KB
testcase_15 AC 317 ms
87,700 KB
testcase_16 AC 170 ms
82,176 KB
testcase_17 AC 168 ms
80,000 KB
testcase_18 AC 221 ms
85,248 KB
testcase_19 AC 318 ms
86,424 KB
testcase_20 AC 318 ms
87,936 KB
testcase_21 AC 318 ms
87,804 KB
権限があれば一括ダウンロードができます

ソースコード

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]
    idx = bisect_left(L, f)
    if idx != N and L[idx] == f:
        ans += w
    # 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