結果

問題 No.2542 Yokan for Two
ユーザー PNJ
提出日時 2023-11-24 23:26:04
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 88 ms / 2,000 ms
コード長 449 bytes
コンパイル時間 391 ms
コンパイル使用メモリ 82,244 KB
実行使用メモリ 63,104 KB
最終ジャッジ日時 2024-09-26 09:48:35
合計ジャッジ時間 4,639 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 40
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = lambda: sys.stdin.readline().strip()

def Map():
  return list(map(int,input().split()))

L,N = Map()
X = Map()
W = []
for i in range(N-1):
  d = X[i+1] - X[i]
  W.append(d)

dp = [0 for i in range(L+1)]
dp[0] = 1
for w in W:
  for l in range(L,-1,-1):
    if dp[l]:
      ll = l + w
      if ll <= L:
        dp[ll] = 1

ans = L
for l in range(L):
  if dp[l]:
    a = l + X[0]
    b = L - a
    ans = min(ans,abs(a-b))
print(ans)
0