結果

問題 No.2408 Lakes and Fish
ユーザー irohasu19_
提出日時 2023-08-13 14:32:24
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
WA  
実行時間 -
コード長 1,073 bytes
コンパイル時間 280 ms
コンパイル使用メモリ 12,928 KB
実行使用メモリ 28,752 KB
最終ジャッジ日時 2024-11-21 10:12:59
合計ジャッジ時間 11,420 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 16 WA * 3
権限があれば一括ダウンロードができます

ソースコード

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

#Lの先頭と末尾に番兵を追加することで場合分けが不要になる
INF = 1000000010
L[:0] = [-INF]
L.append(INF)
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