結果

問題 No.2408 Lakes and Fish
ユーザー irohasu19_
提出日時 2023-08-13 13:46:27
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 670 ms / 2,000 ms
コード長 935 bytes
コンパイル時間 243 ms
コンパイル使用メモリ 12,544 KB
実行使用メモリ 28,600 KB
最終ジャッジ日時 2024-11-21 09:31:34
合計ジャッジ時間 11,373 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 19
権限があれば一括ダウンロードができます

ソースコード

diff #

import bisect

n, m = map(int, input().split())
L = list(map(int, input().split()))
F = []
B = []
W = []

for _ in range(m):
  li = list(map(int, input().split()))
  F.append(li[0])
  B.append(li[1])
  W.append(li[2])

total_cost = 0
is_move = [False]*m
for i in range(m):
  ind_1 = bisect.bisect_left(L, F[i])
  if ind_1>0 and ind_1 < n:
    ind_2 = ind_1 - 1
    cost = min(abs(F[i]-L[ind_1]), abs(F[i]-L[ind_2]))
    if cost < (W[i]-B[i]) :
      is_move[i] = True
      total_cost += cost
    else:
      continue
  elif ind_1 == 0:
    cost = abs(F[i]-L[ind_1])
    if cost < (W[i]-B[i]) :
      is_move[i] = True
      total_cost += cost
  elif ind_1 == n:
    cost = abs(F[i]-L[ind_1-1])
    if cost < (W[i]-B[i]) :
      is_move[i] = True
      total_cost += cost
      
total_score = 0
for j in range(m):
  if is_move[j]:
    total_score += W[j]
  else:
    total_score += B[j]

total_score -= total_cost
print(total_score)


0