結果

問題 No.370 道路の掃除
ユーザー rocoderrocoder
提出日時 2017-07-26 16:12:48
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 35 ms / 2,000 ms
コード長 831 bytes
コンパイル時間 242 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 11,008 KB
最終ジャッジ日時 2024-04-18 00:02:14
合計ジャッジ時間 2,248 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 31 ms
10,752 KB
testcase_01 AC 30 ms
10,752 KB
testcase_02 AC 32 ms
10,752 KB
testcase_03 AC 35 ms
10,880 KB
testcase_04 AC 31 ms
10,752 KB
testcase_05 AC 30 ms
10,880 KB
testcase_06 AC 30 ms
10,752 KB
testcase_07 AC 31 ms
10,880 KB
testcase_08 AC 29 ms
10,880 KB
testcase_09 AC 30 ms
10,752 KB
testcase_10 AC 29 ms
10,752 KB
testcase_11 AC 31 ms
10,880 KB
testcase_12 AC 30 ms
10,880 KB
testcase_13 AC 30 ms
10,752 KB
testcase_14 AC 32 ms
10,752 KB
testcase_15 AC 31 ms
10,752 KB
testcase_16 AC 30 ms
10,752 KB
testcase_17 AC 30 ms
10,752 KB
testcase_18 AC 30 ms
11,008 KB
testcase_19 AC 30 ms
10,880 KB
testcase_20 AC 28 ms
10,752 KB
testcase_21 AC 34 ms
10,880 KB
testcase_22 AC 31 ms
11,008 KB
testcase_23 AC 31 ms
10,880 KB
testcase_24 AC 31 ms
10,880 KB
testcase_25 AC 31 ms
10,880 KB
testcase_26 AC 31 ms
10,880 KB
testcase_27 AC 31 ms
10,752 KB
testcase_28 AC 28 ms
10,752 KB
testcase_29 AC 31 ms
10,880 KB
testcase_30 AC 33 ms
10,752 KB
testcase_31 AC 32 ms
10,752 KB
testcase_32 AC 32 ms
10,880 KB
testcase_33 AC 33 ms
10,880 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#clean
N,M=(int(i) for i in input().split())
s=0
D=[]
nd=0
for i in range(M):
    D.append(int(input()))
    if D[i]>=0 and nd==0:
        s=i
#座標が0以上で最も原点に近い所をs
        nd=1
D.sort()
i=0
while D[i]<0:
    i+=1
s=i
i=0
mi=0
if s+N-1 <M:
    mi=D[s+N-1]
    r=0
    pl=D[s+N-1]
    mp=s+N-1
  #  print (s)
else:
    r=s+N-M
    if s-r>=0:
        mp=M-1
        pl=D[-1]
        nus=-1*D[s-r]
        if nus<pl:
            db=nus
        else:
            db=pl
        mi=pl+nus+db
    #    print (mi)
r+=1
mp-=1
while mp>=s and s-r>=0:
    nus=-1*D[s-r]
 #   print (nus)
    pl=D[mp]
 #   print (mp)
    if nus<pl:
        db=nus
    else:
        db=pl
    m1=pl+nus+db
  #  print (m1)
    if m1<mi:
        mi=m1
    r+=1
    mp-=1
if s-N>=0:
    m1=-1*D[s-N]
    if m1<mi:
        mi=m1
print(mi)
0