結果

問題 No.370 道路の掃除
ユーザー tookunn_1213
提出日時 2016-05-14 00:12:50
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 74 ms / 2,000 ms
コード長 524 bytes
コンパイル時間 83 ms
コンパイル使用メモリ 12,416 KB
実行使用メモリ 10,752 KB
最終ジャッジ日時 2024-10-14 16:49:45
合計ジャッジ時間 2,121 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 34
権限があれば一括ダウンロードができます

ソースコード

diff #

def getDis(d,N):
	now = 0
	pre = 0
	for j in range(len(d)):
		now += abs(abs(pre) - abs(d[j]))
		pre = d[j]
	return now
N,M = map(int,input().split())
D = [int(input())for i in range(M)]
if 0 not in D:
	D.append(0)
	M += 1
	N += 1
D.sort()
ans = 1000000000 + 7
for i in range(M - N + 1):
	if 0 not in D[i:i + N]:continue
	d = sorted(D[i:i + N])
	index0 = d.index(0)
	l = sorted(d[:index0],reverse=True)
	h = d[index0 + 1:]
	low = getDis(l,N)
	high = getDis(h,N)
	ans = min(ans,min(low,high) * 2 + max(low,high))
print (ans)
0