結果

問題 No.2408 Lakes and Fish
ユーザー Navier_BoltzmannNavier_Boltzmann
提出日時 2023-08-25 06:56:46
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 246 ms / 2,000 ms
コード長 738 bytes
コンパイル時間 435 ms
コンパイル使用メモリ 87,216 KB
実行使用メモリ 73,836 KB
最終ジャッジ日時 2023-08-25 10:13:45
合計ジャッジ時間 7,545 ms
ジャッジサーバーID
(参考情報)
judge13 / judge000
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 94 ms
58,772 KB
testcase_01 AC 90 ms
58,940 KB
testcase_02 AC 90 ms
58,872 KB
testcase_03 AC 93 ms
58,548 KB
testcase_04 AC 163 ms
70,676 KB
testcase_05 AC 154 ms
70,680 KB
testcase_06 AC 140 ms
70,500 KB
testcase_07 AC 179 ms
73,512 KB
testcase_08 AC 220 ms
73,836 KB
testcase_09 AC 222 ms
73,484 KB
testcase_10 AC 246 ms
73,664 KB
testcase_11 AC 173 ms
69,256 KB
testcase_12 AC 196 ms
70,792 KB
testcase_13 AC 143 ms
65,928 KB
testcase_14 AC 163 ms
69,216 KB
testcase_15 AC 204 ms
69,572 KB
testcase_16 AC 148 ms
68,348 KB
testcase_17 AC 147 ms
66,072 KB
testcase_18 AC 172 ms
70,072 KB
testcase_19 AC 199 ms
70,420 KB
testcase_20 AC 197 ms
70,144 KB
testcase_21 AC 201 ms
71,032 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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)
0