結果

問題 No.2408 Lakes and Fish
ユーザー Theta
提出日時 2023-10-13 17:03:38
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 573 ms / 2,000 ms
コード長 1,181 bytes
コンパイル時間 438 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 44,236 KB
最終ジャッジ日時 2024-09-15 13:00:38
合計ジャッジ時間 10,438 ms
ジャッジサーバーID
(参考情報)
judge2 / judge6
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 19
権限があれば一括ダウンロードができます

ソースコード

diff #

from bisect import bisect_left
import sys


def printe(*args, end="\n"):
    print(*args, end=end, file=sys.stderr)


def main():
    N, M = map(int, input().split())
    L = list(map(int, input().split()))
    fish = [list(map(int, input().split())) for _ in range(M)]

    fish_lake_dist = []
    for each_fish_coord, _, _ in fish:
        idx = bisect_left(L, each_fish_coord)
        if idx == N:
            fish_lake_dist.append(each_fish_coord - L[-1])
            continue
        if L[idx] == each_fish_coord:
            fish_lake_dist.append(0)
            continue
        if idx == 0:
            fish_lake_dist.append(L[0] - each_fish_coord)
            continue

        fish_lake_dist.append(
            min(
                each_fish_coord - L[idx - 1],
                L[idx] - each_fish_coord))
    printe(fish_lake_dist)

    strong_cost_diff = 0
    for (_, fish_g_s, fish_w_s), dist in zip(fish, fish_lake_dist):
        if dist == 0:
            strong_cost_diff += fish_w_s
            continue
        strong_cost_diff += max(
            fish_g_s,
            fish_w_s - dist
        )
    print(strong_cost_diff)


if __name__ == "__main__":
    main()
0