結果
問題 | No.2408 Lakes and Fish |
ユーザー |
|
提出日時 | 2023-08-25 06:56:46 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 178 ms / 2,000 ms |
コード長 | 738 bytes |
コンパイル時間 | 334 ms |
コンパイル使用メモリ | 81,408 KB |
実行使用メモリ | 92,928 KB |
最終ジャッジ日時 | 2024-12-23 16:55:23 |
合計ジャッジ時間 | 5,349 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 19 |
ソースコード
from collections import * from itertools import * from functools import * from heapq import * import sys,math input = sys.stdin.readline N,M = map(int,input().split()) L = list(map(int,input().split())) X = [] s = 0 for _ in range(M): f,b,w = map(int,input().split()) s += b is_ok = lambda x: L[x]<=f if is_ok(N-1): x = N-1 X.append(w-b-abs(L[x]-f)) continue if not is_ok(0): X.append(w-b-abs(L[0]-f)) continue y = N-1 x = 0 while y-x>1: mid = (y+x)//2 if is_ok(mid): x = mid else: y = mid X.append(w-b-min(abs(L[x]-f),abs(L[y]-f))) X.sort(reverse=True) for x in X: if x<=0: break s += x print(s)