problem_id
stringlengths 6
6
| user_id
stringlengths 10
10
| time_limit
float64 1k
8k
| memory_limit
float64 262k
1.05M
| problem_description
stringlengths 48
1.55k
| codes
stringlengths 35
98.9k
| status
stringlengths 28
1.7k
| submission_ids
stringlengths 28
1.41k
| memories
stringlengths 13
808
| cpu_times
stringlengths 11
610
| code_sizes
stringlengths 7
505
|
---|---|---|---|---|---|---|---|---|---|---|
p03273 | u934788990 | 2,000 | 1,048,576 | There is a grid of squares with H horizontal rows and W vertical columns. The square at the i-th row from the top and the j-th column from the left is represented as (i, j). Each square is black or white. The color of the square is given as an H-by-W matrix (a_{i, j}). If a_{i, j} is `.`, the square (i, j) is white; if a_{i, j} is `#`, the square (i, j) is black. Snuke is compressing this grid. He will do so by repeatedly performing the following operation while there is a row or column that consists only of white squares: * Operation: choose any one row or column that consists only of white squares, remove it and delete the space between the rows or columns. It can be shown that the final state of the grid is uniquely determined regardless of what row or column is chosen in each operation. Find the final state of the grid. | ["h, w = map(int, input().split())\na = [''] * h\nfor i in range(h):\n\ta[i] = input()\nprint(a)\nrow = [False] * h\ncol = [False] * w\nfor i in range(h):\n\tfor j in range(w):\n\t\tif a[i][j] == '#':\n\t\t\trow[i] = True\n\t\t\tcol[j] = True\nprint(row)\nprint(col)\nfor i in range(h):\n\tif row[i]:\n\t\tfor j in range(w):\n\t\t\tif col[j]:\n\t\t\t\tprint(a[i][j], end = '')\n\t\tprint()\n", "h, w = map(int, input().split())\na = [''] * h\nfor i in range(h):\n\ta[i] = input()\n\nrow = [False] * h\ncol = [False] * w\nfor i in range(h):\n\tfor j in range(w):\n\t\tif a[i][j] == '#':\n\t\t\trow[i] = True\n\t\t\tcol[j] = True\nfor i in range(h):\n\tif row[i]:\n\t\tfor j in range(w):\n\t\t\tif col[j]:\n\t\t\t\tprint(a[i][j], end = '')\n\t\tprint()"] | ['Wrong Answer', 'Accepted'] | ['s551101918', 's934610343'] | [4212.0, 4468.0] | [30.0, 30.0] | [347, 316] |
p03273 | u934868410 | 2,000 | 1,048,576 | There is a grid of squares with H horizontal rows and W vertical columns. The square at the i-th row from the top and the j-th column from the left is represented as (i, j). Each square is black or white. The color of the square is given as an H-by-W matrix (a_{i, j}). If a_{i, j} is `.`, the square (i, j) is white; if a_{i, j} is `#`, the square (i, j) is black. Snuke is compressing this grid. He will do so by repeatedly performing the following operation while there is a row or column that consists only of white squares: * Operation: choose any one row or column that consists only of white squares, remove it and delete the space between the rows or columns. It can be shown that the final state of the grid is uniquely determined regardless of what row or column is chosen in each operation. Find the final state of the grid. | ["h,w = map(int,input().split())\na = list()\n\nfor i in range(h):\n a.append(list(map(int, input().split())))\n\nh_blank = [False]*h\nw_blank = [False]*w\nfor i in range(h):\n blank = True\n for j in range(w):\n if a[i][j] == '#':\n blank = False\n break\n if blank:\n h_blank[i] = True\n\nfor i in range(w):\n blank = True\n for j in range(h):\n if a[j][i] == '#':\n blank = False\n break\n if blank:\n w_blank[i] = True\n\nfor i in range(h):\n for j in range(w):\n if h_blank[i] or w_blank[j]:\n continue\n print(a[i][j])", "h,w = map(int,input().split())\na = list()\n\nfor i in range(h):\n a.append(input())\n\nh_blank = [False]*h\nw_blank = [False]*w\nfor i in range(h):\n blank = True\n for j in range(w):\n if a[i][j] == '#':\n blank = False\n break\n if blank:\n h_blank[i] = True\n\nfor i in range(w):\n blank = True\n for j in range(h):\n if a[j][i] == '#':\n blank = False\n break\n if blank:\n w_blank[i] = True\n\nfor i in range(h):\n for j in range(w):\n if h_blank[i] or w_blank[j]:\n continue\n print(a[i][j])", "h,w = map(int,input().split())\na = list()\n\nfor i in range(h):\n a.append(list(map(int, input().split())))\n\nh_blank = [False]*h\nw_blank = [False]*w\nfor i in range(h):\n blank = True\n for j in range(w):\n if a[i][j] == '#':\n blank = False\n break\n if blank:\n h_blank[i] = True\n\nfor i in range(w):\n blank = True\n for j in range(h):\n if a[j][i] == '#':\n blank = False\n break\n if blank:\n w_blank[i] = True\n\nfor i in range(h):\n for j in range(w):\n if h_blank[i] or w_blank[j]:\n continue\n print(a[i][]j)", "h,w = map(int,input().split())\na = list()\n\nfor i in range(h):\n a.append(input())\n\nh_blank = [False]*h\nw_blank = [False]*w\nfor i in range(h):\n blank = True\n for j in range(w):\n if a[i][j] == '#':\n blank = False\n break\n if blank:\n h_blank[i] = True\n\nfor i in range(w):\n blank = True\n for j in range(h):\n if a[j][i] == '#':\n blank = False\n break\n if blank:\n w_blank[i] = True\n\nfor i in range(h):\n if h_blank[i]:\n continue\n for j in range(w):\n if w_blank[j]:\n continue\n print(a[i][j], end='')\n print('')"] | ['Runtime Error', 'Wrong Answer', 'Runtime Error', 'Accepted'] | ['s639228058', 's778071149', 's888220439', 's866332814'] | [3064.0, 3700.0, 3064.0, 4468.0] | [18.0, 26.0, 17.0, 29.0] | [543, 519, 543, 555] |
p03273 | u937529125 | 2,000 | 1,048,576 | There is a grid of squares with H horizontal rows and W vertical columns. The square at the i-th row from the top and the j-th column from the left is represented as (i, j). Each square is black or white. The color of the square is given as an H-by-W matrix (a_{i, j}). If a_{i, j} is `.`, the square (i, j) is white; if a_{i, j} is `#`, the square (i, j) is black. Snuke is compressing this grid. He will do so by repeatedly performing the following operation while there is a row or column that consists only of white squares: * Operation: choose any one row or column that consists only of white squares, remove it and delete the space between the rows or columns. It can be shown that the final state of the grid is uniquely determined regardless of what row or column is chosen in each operation. Find the final state of the grid. | ['a = list(map(int,input().split()))\nh = a[0]\nw = a[1]\nli=[input() for i in range(h)]\n\nans = 0\nminans = 0\nflag = 0\nrow = [False] * h\ncol = [False] * w\nfor i in range(h):\n for j in range(w):\n if li[i][j] == "#":\n row[i]=True\n col[j]= True\nfor i in range(h):\n if row[i]:\n for j in range(w):\n if col[j]:\n print(li[i][j],end =" ")\n \n print()\n', 'a = list(map(int,input().split()))\nh = a[0]\nw = a[1]\nli=[input() for i in range(h)]\n\nans = 0\nminans = 0\nflag = 0\nrow = [False] * h\ncol = [False] * w\nfor i in range(h):\n for j in range(w):\n if li[i][j] == "#":\n row[i]=True\n col[j]= True\nfor i in range(h):\n if row[i]:\n for j in range(w):\n if col[j]:\n print(li[i][j],end ="")\n \n print()'] | ['Wrong Answer', 'Accepted'] | ['s921306826', 's631170522'] | [3700.0, 4468.0] | [30.0, 30.0] | [426, 424] |
p03273 | u940568210 | 2,000 | 1,048,576 | There is a grid of squares with H horizontal rows and W vertical columns. The square at the i-th row from the top and the j-th column from the left is represented as (i, j). Each square is black or white. The color of the square is given as an H-by-W matrix (a_{i, j}). If a_{i, j} is `.`, the square (i, j) is white; if a_{i, j} is `#`, the square (i, j) is black. Snuke is compressing this grid. He will do so by repeatedly performing the following operation while there is a row or column that consists only of white squares: * Operation: choose any one row or column that consists only of white squares, remove it and delete the space between the rows or columns. It can be shown that the final state of the grid is uniquely determined regardless of what row or column is chosen in each operation. Find the final state of the grid. | ['import numpy as np\n\nh, w = tuple(map(int, input().split()))\nmatrix = np.zeros((h, w), dtype=bool)\nfor i in range(h):\n row = np.array(input().split())\n matrix[i, :] = row == "."\n\nfor i in range(h)[::-1]:\n if np.all(matrix[i, :]):\n matrix = np.delete(matrix, i, 0)\n\nfor i in range(w)[::-1]:\n if np.all(matrix[:, i]):\n matrix = np.delete(matrix, i, 1)\n\nmatrix = np.where(matrix, ".", "#")\nfor row in matrix:\n for e in row:\n print(e+" ", end="")\n print("\\b")\n', '\nh, w = map(int, input().split())\n\nmat = [input() for _ in range(h)]\n\n\n[mat.remove(row) for row in mat[::-1] if ("#" not in row)]\n\nshowCol = [i for i in range(w) if "#" in [row[i] for row in mat]]\n\n\nprint("\\n".join(["".join([row[c] for c in showCol]) for row in mat]))\n'] | ['Wrong Answer', 'Accepted'] | ['s174191731', 's252609642'] | [22672.0, 3060.0] | [350.0, 19.0] | [494, 407] |
p03273 | u953379577 | 2,000 | 1,048,576 | There is a grid of squares with H horizontal rows and W vertical columns. The square at the i-th row from the top and the j-th column from the left is represented as (i, j). Each square is black or white. The color of the square is given as an H-by-W matrix (a_{i, j}). If a_{i, j} is `.`, the square (i, j) is white; if a_{i, j} is `#`, the square (i, j) is black. Snuke is compressing this grid. He will do so by repeatedly performing the following operation while there is a row or column that consists only of white squares: * Operation: choose any one row or column that consists only of white squares, remove it and delete the space between the rows or columns. It can be shown that the final state of the grid is uniquely determined regardless of what row or column is chosen in each operation. Find the final state of the grid. | ['h,w = map(int,input().split())\n\nf = []\n\nfor i in range(h):\n f.append(list(input()))\n \nfor i in f:\n if i == ["."]*len(i):\n f.remove(i)\n \nf2 = []\n\nfor i in range(w):\n s = []\n \n for k in f:\n s.append(k[i])\n \n f2.append(s)\n \nfor i in f2:\n if i == ["."]*len(i):\n f2.remove(i)\n \nfor i in f2:\n for s in range(len(i)-1):\n print(i[s],end = "")\n \n print(i[-1])', 'h,w = map(int,input().split())\n\nf = []\n\nfor i in range(h):\n f.append(list(input()))\n \na = []\n \nfor i in range(len(f)):\n if f[i] == ["."]*len(f[i]):\n a.append(i)\n \nfor i in a:\n del f[i]\n for s in range(len(a)):\n a[s] -= 1\n \nf2 = []\n\nfor i in range(w):\n s = []\n \n for k in f:\n s.append(k[i])\n \n f2.append(s)\n \nb = []\n \nfor i in range(len(f2)):\n if f2[i] == ["."]*len(f2[i]):\n b.append(i)\n \nfor i in b:\n del f2[i]\n for s in range(len(b)):\n b[s] -= 1\n \nff = []\n\nfor i in range(len(f2[0])):\n s = []\n \n for k in f2:\n s.append(k[i])\n \n ff.append(s)\n \nfor i in ff:\n for s in range(len(i)-1):\n print(i[s],end = "")\n \n print(i[-1])'] | ['Wrong Answer', 'Accepted'] | ['s041410212', 's629109307'] | [4596.0, 4724.0] | [29.0, 31.0] | [435, 785] |
p03273 | u955251526 | 2,000 | 1,048,576 | There is a grid of squares with H horizontal rows and W vertical columns. The square at the i-th row from the top and the j-th column from the left is represented as (i, j). Each square is black or white. The color of the square is given as an H-by-W matrix (a_{i, j}). If a_{i, j} is `.`, the square (i, j) is white; if a_{i, j} is `#`, the square (i, j) is black. Snuke is compressing this grid. He will do so by repeatedly performing the following operation while there is a row or column that consists only of white squares: * Operation: choose any one row or column that consists only of white squares, remove it and delete the space between the rows or columns. It can be shown that the final state of the grid is uniquely determined regardless of what row or column is chosen in each operation. Find the final state of the grid. | ['h, w = map(int, input().split())\nhlist = []\nwlist = []\na = [list(input()) for i in range(h)]\nfor i in range(h):\n for j in range(w):\n if a[i][j] == "#":\n hlist.append(i)\n wlist.append(j)\nprint(hlist,wlist)\nfor i in set(hlist):\n for j in set(wlist):\n print(a[i][j], end ="")\n print()', 'h, w = map(int, input().split())\nhlist = []\nwlist = []\na = [list(input()) for i in range(h)]\nfor i in range(h):\n for j in range(w):\n if a[i][j] == "#":\n hlist.append(i)\n wlist.append(j)\nfor i in set(hlist):\n for j in set(wlist):\n print(a[i][j], end ="")\n print()'] | ['Wrong Answer', 'Accepted'] | ['s464660925', 's311705292'] | [4980.0, 4724.0] | [49.0, 46.0] | [326, 307] |
p03273 | u957872856 | 2,000 | 1,048,576 | There is a grid of squares with H horizontal rows and W vertical columns. The square at the i-th row from the top and the j-th column from the left is represented as (i, j). Each square is black or white. The color of the square is given as an H-by-W matrix (a_{i, j}). If a_{i, j} is `.`, the square (i, j) is white; if a_{i, j} is `#`, the square (i, j) is black. Snuke is compressing this grid. He will do so by repeatedly performing the following operation while there is a row or column that consists only of white squares: * Operation: choose any one row or column that consists only of white squares, remove it and delete the space between the rows or columns. It can be shown that the final state of the grid is uniquely determined regardless of what row or column is chosen in each operation. Find the final state of the grid. | ['h,w = map(int,input().split())\na = [[j for j in input()] for i in range(h)]\nb = [x for x in a if "#" in x]\nprint(*b)\nc = zip(*[y for y in zip(*b) if "#" in y])\n#print(list(c))\nfor d in c:\n print("".join(d))', 'h,w = map(int,input().split())\na = [[j for j in input()] for i in range(h)]\nb = [x for x in a if "#" in x]\n#print(*b)\nc = zip(*[y for y in zip(*b) if "#" in y])\n#print(list(c))\nfor d in c:\n print("".join(d))'] | ['Wrong Answer', 'Accepted'] | ['s263839198', 's348916020'] | [3188.0, 3188.0] | [20.0, 18.0] | [207, 208] |
p03273 | u961595602 | 2,000 | 1,048,576 | There is a grid of squares with H horizontal rows and W vertical columns. The square at the i-th row from the top and the j-th column from the left is represented as (i, j). Each square is black or white. The color of the square is given as an H-by-W matrix (a_{i, j}). If a_{i, j} is `.`, the square (i, j) is white; if a_{i, j} is `#`, the square (i, j) is black. Snuke is compressing this grid. He will do so by repeatedly performing the following operation while there is a row or column that consists only of white squares: * Operation: choose any one row or column that consists only of white squares, remove it and delete the space between the rows or columns. It can be shown that the final state of the grid is uniquely determined regardless of what row or column is chosen in each operation. Find the final state of the grid. | ["# -*- coding: utf-8 -*-\nfrom sys import stdin\n\nns = lambda: stdin.readline()[:-1] \nni = lambda: int(stdin.readline()) # N = ni()\nna = lambda: list(map(int, stdin.readline().split())) # Arr = na()\n\nH, W = na()\nGrid = []\nfor _ in range(H):\n s = ns()\n if '#' in s:\n Grid.append(list(s))\n\nh = len(Grid)\nres = []\nfor i in range(W):\n s = ''\n for j in range(h):\n s += Grid[j][i]\n if '#' in s:\n res.append(s)\n\nfor i in range(len(res[0])):\n s = ''\n for j in range(len(res)):\n s += res[-1-j][i]\n print(s)\n", "# -*- coding: utf-8 -*-\nfrom sys import stdin\n\nns = lambda: stdin.readline()[:-1] \nni = lambda: int(stdin.readline()) # N = ni()\nna = lambda: list(map(int, stdin.readline().split())) # Arr = na()\n\nH, W = na()\nGrid = []\nfor _ in range(H):\n s = ns()\n if '#' in s:\n Grid.append(list(s))\n\nh = len(Grid)\nres = []\nfor i in range(W):\n s = ''\n for j in range(h):\n s += Grid[j][i]\n if '#' in s:\n res.append(s)\n\nfor i in range(len(res[0])):\n s = ''\n for j in range(len(res)):\n s += res[j][i]\n print(s)\n\n"] | ['Wrong Answer', 'Accepted'] | ['s467307690', 's232054647'] | [3188.0, 3188.0] | [22.0, 22.0] | [557, 555] |
p03273 | u971237642 | 2,000 | 1,048,576 | There is a grid of squares with H horizontal rows and W vertical columns. The square at the i-th row from the top and the j-th column from the left is represented as (i, j). Each square is black or white. The color of the square is given as an H-by-W matrix (a_{i, j}). If a_{i, j} is `.`, the square (i, j) is white; if a_{i, j} is `#`, the square (i, j) is black. Snuke is compressing this grid. He will do so by repeatedly performing the following operation while there is a row or column that consists only of white squares: * Operation: choose any one row or column that consists only of white squares, remove it and delete the space between the rows or columns. It can be shown that the final state of the grid is uniquely determined regardless of what row or column is chosen in each operation. Find the final state of the grid. | ['# -*- coding: utf-8 -*-\n\nh,w = map(int, input().split())\n\na = [list(input()) for _ in range(h)]\n\na_new = []\nfor row in a:\n cache = set(row)\n if (len(cache) == 1) and (row[0] == "."):\n pass\n else:\n a_new.append(row)\n\nn_h = len(a_new)\nn_w = len(a_new[0])\n\nb_new = [["" for _ in range(n_h)] for _ in range(n_w)]\n\nfor i in range(n_h):\n for j in range(n_w):\n b_new[j][i]=a_new[i][j]\n\n\na = b_new\n\na_new = []\nfor row in a:\n cache = set(row)\n if (len(cache) == 1) and (row[0] == "."):\n pass\n else:\n a_new.append(row)\n\n\nn_h = len(a_new)\nn_w = len(a_new[0])\n\nb_new = [["" for _ in range(n_h)] for _ in range(n_w)]\n\nfor i in range(n_h):\n for j in range(n_w):\n b_new[j][i]=a_new[i][j]\n\n\nans = ""\n\nfor i in range(n_h):\n for j in range(n_w):\n ans += b_new[i][j]\n ans += "\\n"\n\nprint(ans)', '# -*- coding: utf-8 -*-\n\nh, w = map(int, input().split())\na = [""]*h\nfor i in range(h):\n a[i] = input()\n\nrow = [False] * h\ncol = [False] * w\n\n\nfor i in range(h):\n for j in range(w):\n if a[i][j] == "#":\n row[i] = True\n col[j] = True\n\n\nfor i in range(h):\n if row[i]:\n for j in range(w):\n if col[j]:\n print(a[i][j], end = "")\n\n print()\n'] | ['Runtime Error', 'Accepted'] | ['s805162765', 's612997385'] | [3316.0, 4468.0] | [24.0, 30.0] | [851, 411] |
p03273 | u975481854 | 2,000 | 1,048,576 | There is a grid of squares with H horizontal rows and W vertical columns. The square at the i-th row from the top and the j-th column from the left is represented as (i, j). Each square is black or white. The color of the square is given as an H-by-W matrix (a_{i, j}). If a_{i, j} is `.`, the square (i, j) is white; if a_{i, j} is `#`, the square (i, j) is black. Snuke is compressing this grid. He will do so by repeatedly performing the following operation while there is a row or column that consists only of white squares: * Operation: choose any one row or column that consists only of white squares, remove it and delete the space between the rows or columns. It can be shown that the final state of the grid is uniquely determined regardless of what row or column is chosen in each operation. Find the final state of the grid. | ['h, w = map(int, input().split())\na = [input() for w in range(h)]\n\nfor i in range(h)[::-1]:\n if "#" not in a[i]:\n del a[i]\n h -= 1\nprint(a)\n\nn = []\nfor j in range(w):\n print("j=" + str(j))\n m = ["".join(t[j] for t in a)]\n if "#" in m[0]:\n n += m\nprint(n)\n\nfor k in range(h):\n print("".join(n[k]))\n', 'h, w = map(int, input().split())\na = [input() for w in range(h)]\n\nfor i in range(h)[::-1]:\n if "#" not in a[i]:\n del a[i]\n h -= 1\n\nn = []\nfor j in range(w):\n m = ["".join(t[j] for t in a)]\n if "#" in m[0]:\n n += m\n\nfor k in range(h):\n print("".join(u[k] for u in n))\n'] | ['Runtime Error', 'Accepted'] | ['s210563612', 's275532335'] | [3064.0, 3060.0] | [19.0, 19.0] | [332, 300] |
p03273 | u982198202 | 2,000 | 1,048,576 | There is a grid of squares with H horizontal rows and W vertical columns. The square at the i-th row from the top and the j-th column from the left is represented as (i, j). Each square is black or white. The color of the square is given as an H-by-W matrix (a_{i, j}). If a_{i, j} is `.`, the square (i, j) is white; if a_{i, j} is `#`, the square (i, j) is black. Snuke is compressing this grid. He will do so by repeatedly performing the following operation while there is a row or column that consists only of white squares: * Operation: choose any one row or column that consists only of white squares, remove it and delete the space between the rows or columns. It can be shown that the final state of the grid is uniquely determined regardless of what row or column is chosen in each operation. Find the final state of the grid. | ["N, M = map(int, input().split())\na = [input() for i in range(N)]\ncounter = 0\nnumlist = []\ndelMlist = []\n\nfor i in range(N):\n #print(a[i])\n if a[i].count('#') == 0:\n delMlist.append(i)\n#print(delMlist)\n\nfor i in delMlist:\n a.pop(i-counter)\n #print(a)\n counter += 1\nprint('---------')\n#print(a)\nN = N - len(delMlist)\n#print(N)\nnewlist = []\nfor i in range(N): \n for j in range(M):\n if a[i][j] == '.' :\n numlist.append([i,j])\n newlist.append([a[i]])\nllist = []\nfor i in range(N):\n \n llist.append(list(a[i]))\n\ncounter1 = 0\nfst = ''\ndelNlist = []\n#print(N)\nfor i in range(M):\n for j in range(N):\n #print(j)\n if llist[j][i] == '.':\n counter1 += 1\n if counter1 == N:\n delNlist.append(i)\n counter1 = 0\n#print(delNlist)\n#print('---------')\n#anslist = []\ncounter2 = 0\nif delNlist != []:\n for h in delNlist:\n for i in range(N):\n a[i] = (a[i][:h-counter2] + a[i][h+1-counter2:])\n counter2 += 1\nfor i in a:\n print(i)\n#print(a) ", "N, M = map(int, input().split())\na = [input() for i in range(N)]\ncounter = 0\nnumlist = []\ndelMlist = []\n\nfor i in range(N):\n #print(a[i])\n if a[i].count('#') == 0:\n delMlist.append(i)\n#print(delMlist)\n\nfor i in delMlist:\n a.pop(i-counter)\n #print(a)\n counter += 1\n#print('---------')\n#print(a)\nN = N - len(delMlist)\n#print(N)\nnewlist = []\nfor i in range(N): \n for j in range(M):\n if a[i][j] == '.' :\n numlist.append([i,j])\n newlist.append([a[i]])\nllist = []\nfor i in range(N):\n \n llist.append(list(a[i]))\n\ncounter1 = 0\nfst = ''\ndelNlist = []\n#print(N)\nfor i in range(M):\n for j in range(N):\n #print(j)\n if llist[j][i] == '.':\n counter1 += 1\n if counter1 == N:\n delNlist.append(i)\n counter1 = 0\n#print(delNlist)\n#print('---------')\n#anslist = []\ncounter2 = 0\nif delNlist != []:\n for h in delNlist:\n for i in range(N):\n a[i] = (a[i][:h-counter2] + a[i][h+1-counter2:])\n counter2 += 1\nfor i in a:\n print(i)\n#print(a) \n "] | ['Wrong Answer', 'Accepted'] | ['s611179705', 's963217674'] | [4084.0, 4084.0] | [25.0, 25.0] | [1080, 1090] |
p03273 | u987164499 | 2,000 | 1,048,576 | There is a grid of squares with H horizontal rows and W vertical columns. The square at the i-th row from the top and the j-th column from the left is represented as (i, j). Each square is black or white. The color of the square is given as an H-by-W matrix (a_{i, j}). If a_{i, j} is `.`, the square (i, j) is white; if a_{i, j} is `#`, the square (i, j) is black. Snuke is compressing this grid. He will do so by repeatedly performing the following operation while there is a row or column that consists only of white squares: * Operation: choose any one row or column that consists only of white squares, remove it and delete the space between the rows or columns. It can be shown that the final state of the grid is uniquely determined regardless of what row or column is chosen in each operation. Find the final state of the grid. | ['from sys import stdin\nimport numpy as np\n\nh,w= [int(x) for x in stdin.readline().rstrip().split()]\n\nli = [["" for i in range(w)]for j in range(h)]\n\nfor i in range(h):\n s = stdin.readline().rstrip()\n for j in range(w):\n li[i][j] = s[j]\n\nli = np.asarray([s for s in li if s != [\'.\']*w]).T.tolist()\nli = np.asarray([s for s in li if s != [\'.\']*len(li[0])]).T.tolist()\n\nfor i in range(len(li)):\n print(*li[i])', 'from sys import stdin,setrecursionlimit\nsetrecursionlimit(10 ** 7)\nh,w = map(int,stdin.readline().rstrip().split())\nli = [["" for i in range(w)]for j in range(h)]\nfor i in range(h):\n s = stdin.readline().rstrip()\n for j in range(w):\n li[i][j] = s[j]\nlin = []\nfor i in li:\n if i != ["."]*w:\n lin.append(i)\nout = []\nfor i in range(w):\n flag = True\n for j in range(len(lin)):\n if lin[j][i] == "#":\n flag = False\n if flag:\n out.append(i)\n\nlis = []\nfor i in lin:\n case = []\n for j,k in enumerate(i):\n if j in out:\n continue\n case.append(k)\n lis.append(case)\n\nfor i in lis:\n print("".join(i))'] | ['Wrong Answer', 'Accepted'] | ['s620446919', 's878437113'] | [13136.0, 3188.0] | [161.0, 23.0] | [421, 680] |
p03273 | u991567869 | 2,000 | 1,048,576 | There is a grid of squares with H horizontal rows and W vertical columns. The square at the i-th row from the top and the j-th column from the left is represented as (i, j). Each square is black or white. The color of the square is given as an H-by-W matrix (a_{i, j}). If a_{i, j} is `.`, the square (i, j) is white; if a_{i, j} is `#`, the square (i, j) is black. Snuke is compressing this grid. He will do so by repeatedly performing the following operation while there is a row or column that consists only of white squares: * Operation: choose any one row or column that consists only of white squares, remove it and delete the space between the rows or columns. It can be shown that the final state of the grid is uniquely determined regardless of what row or column is chosen in each operation. Find the final state of the grid. | ['h, w = map(int, input().split())\na = []\ndelrow = []\ndelcol = []\n\n\nfor i in range(h):\n a.append(list(input()))\n\nfor i in range(h):\n print(set(a[i]))\n if set(a[i]) == {"."}:\n delrow.append(i)\n\nfor i in range(w):\n print(set(a[0:w][i]))\n if set(a[0:w][i]) == {"."}:\n delcol.append(i)\n \nfor i in delrow [::-1]: \n del a[i]\nfor i in delcol [::-1]: \n for j in range(len(a)):\n del a[j][i]\n\nfor i in range(len(a)):\n print(*a[i], sep="")', 'h, w = map(int, input().split())\na = []\ndelrow = []\ndelcol = []\n\n\nfor i in range(h):\n a.append(list(input()))\n\nfor i in range(h):\n if set(a[i]) == {"."}:\n delrow.append(i)\n\nfor i in range(w):\n if set(a[0:w][i]) == {"."}:\n delcol.append(i)\n \nfor i in delrow [::-1]: \n del a[i]\nfor i in delcol [::-1]: \n for j in range(len(a)):\n del a[j][i]\n\nfor i in range(len(a)):\n print(*a[i], sep="")', 'h, w = map(int, input().split())\na = []\ncolrow = []\n\nfor i in range(h):\n b = list(input())\n if set(b) == {"."}:\n continue\n a.append(b)\n\nfor x in zip(*a): \n if set(x) == {"."}:\n continue\n colrow.append(x)\n\nfor x in zip(*colrow):\n print(*x, sep="")'] | ['Runtime Error', 'Runtime Error', 'Accepted'] | ['s208853904', 's273971622', 's311525808'] | [4340.0, 4596.0, 4596.0] | [22.0, 21.0, 22.0] | [504, 457, 326] |
p03273 | u992910889 | 2,000 | 1,048,576 | There is a grid of squares with H horizontal rows and W vertical columns. The square at the i-th row from the top and the j-th column from the left is represented as (i, j). Each square is black or white. The color of the square is given as an H-by-W matrix (a_{i, j}). If a_{i, j} is `.`, the square (i, j) is white; if a_{i, j} is `#`, the square (i, j) is black. Snuke is compressing this grid. He will do so by repeatedly performing the following operation while there is a row or column that consists only of white squares: * Operation: choose any one row or column that consists only of white squares, remove it and delete the space between the rows or columns. It can be shown that the final state of the grid is uniquely determined regardless of what row or column is chosen in each operation. Find the final state of the grid. | ['H,W=map(int,input().split())\nA=[list(input()) for i in range(H)]\nprint(A)\n\n', "\n# import copy\n# import fractions\n# import math\n# import numpy as np\n# from collections import Counter, deque\n# from itertools import accumulate, permutations, combinations, combinations_with_replacement, product\n\n\ndef resolve():\n h, w = map(int, input().split())\n A = [[_ for _ in input()] for _ in range(h)]\n B = [i for i in A if '#' in i]\n C = zip(*[i for i in zip(*B) if '#' in i])\n for i in C:\n print(*i, sep='')\n\n # print(*C,sep='')\n\n\nresolve()"] | ['Wrong Answer', 'Accepted'] | ['s524878459', 's402230790'] | [3188.0, 4596.0] | [18.0, 21.0] | [551, 494] |
p03273 | u993435350 | 2,000 | 1,048,576 | There is a grid of squares with H horizontal rows and W vertical columns. The square at the i-th row from the top and the j-th column from the left is represented as (i, j). Each square is black or white. The color of the square is given as an H-by-W matrix (a_{i, j}). If a_{i, j} is `.`, the square (i, j) is white; if a_{i, j} is `#`, the square (i, j) is black. Snuke is compressing this grid. He will do so by repeatedly performing the following operation while there is a row or column that consists only of white squares: * Operation: choose any one row or column that consists only of white squares, remove it and delete the space between the rows or columns. It can be shown that the final state of the grid is uniquely determined regardless of what row or column is chosen in each operation. Find the final state of the grid. | ['H,W = map(int,input().split())\n\nA = ""\n\nfor _ in range(H):\n s = input()\n if len(set(s)) == 1 and s == "." * W:\n H -= 1\n else:\n for i in s:\n A.append(i)\n\nif len(A) == 0:\n print(A)\n\nelse:\n M = []\n\n for i in range(W):\n if A[i] == ".":\n for j in range(i + W,H * W,W):\n if A[j] == "#":\n break\n else:\n M.append(i)\n\n A = [A[i] for i in range(H * W) if not (i % W) in M]\n W = W - len(M)\n \n S = ""\n \n for i in range(H * W):\n S += A[i]\n if (i + 1) % W == 0:\n print(S)\n S = ""', 'H,W = map(int,input().split())\n\nA = ""\n\nfor _ in range(H):\n s = input()\n if len(set(s)) == 1 and s == "." * W:\n H -= 1\n else:\n for i in s:\n A += i\n\nif len(A) == 0:\n print(A)\n\nelse:\n M = []\n\n for i in range(W):\n if A[i] == ".":\n for j in range(i + W,H * W,W):\n if A[j] == "#":\n break\n else:\n M.append(i)\n\n A = [A[i] for i in range(H * W) if not (i % W) in M]\n W = W - len(M)\n \n S = ""\n \n for i in range(H * W):\n S += A[i]\n if (i + 1) % W == 0:\n print(S)\n S = ""'] | ['Runtime Error', 'Accepted'] | ['s487765922', 's842131549'] | [3064.0, 3188.0] | [17.0, 24.0] | [540, 535] |
p03273 | u998771223 | 2,000 | 1,048,576 | There is a grid of squares with H horizontal rows and W vertical columns. The square at the i-th row from the top and the j-th column from the left is represented as (i, j). Each square is black or white. The color of the square is given as an H-by-W matrix (a_{i, j}). If a_{i, j} is `.`, the square (i, j) is white; if a_{i, j} is `#`, the square (i, j) is black. Snuke is compressing this grid. He will do so by repeatedly performing the following operation while there is a row or column that consists only of white squares: * Operation: choose any one row or column that consists only of white squares, remove it and delete the space between the rows or columns. It can be shown that the final state of the grid is uniquely determined regardless of what row or column is chosen in each operation. Find the final state of the grid. | ["import numpy as np\nWH='.'\nBK='#'\nx=input()\nx=x.split()\nH=int(x[0])\nW=int(x[1])\na=[[] for i in range(H)]\nnum=[]\nnumnum=0\nfor i in range(H):\n x=input()\n for j in range(W):\n a[i].append(x[j])\nfor i in range(H):\n flag=0\n for j in range(W):\n if a[i][j]==WH:\n flag=flag+1\n else:\n flag=flag-1\n if flag==W:\n num.append(i)\n numnum=numnum+1\nfor i in range(numnum):\n a.pop(num[i])\nH=H-numnum\na_n=np.array(a)\ntr=a_n.T\nnum=[]\nnumnum=0\nfor i in range(W):\n flag=0\n for j in range(H):\n if tr[i][j]==WH:\n flag=flag+1\n else:\n flag=flag-1\n if flag==H:\n num.append(i)\n numnum=numnum+1\nfor i in range(numnum):\n a=np.delete(tr,num[i],0)\na=a.T\nprint(a)", "import numpy as np\nWH='.'\nBK='#'\nx=input()\nx=x.split()\nH=int(x[0])\nW=int(x[1])\na=[[] for i in range(H)]\nnum=[]\nnumnum=0\nfor i in range(H):\n x=input()\n for j in range(W):\n a[i].append(x[j])\nfor i in range(H):\n flag=0\n for j in range(W):\n if a[i][j]==WH:\n flag=flag+1\n else:\n flag=flag-1\n if flag==W:\n num.append(i)\n numnum=numnum+1\nfor i in range(numnum):\n a.pop(num[i])\nH=H-numnum\na_n=np.array(a)\ntr=a_n.T\nnum=[]\nnumnum=0\nfor i in range(W):\n flag=0\n for j in range(H):\n if tr[i][j]==WH:\n flag=flag+1\n else:\n flag=flag-1\n if flag==H:\n num.append(i)\n numnum=numnum+1\nfor i in range(numnum):\n a=np.delete(tr,num[i],0)\na_n=np.array(a)\na=a_n.T\nprint(a)\n\n \n ", "import numpy as np\nWH='.'\nBK='#'\nx=input()\nx=x.split()\nH=int(x[0])\nW=int(x[1])\na=[[] for i in range(H)]\nnum=[]\nnumnum=0\nfor i in range(H):\n x=input()\n for j in range(W):\n a[i].append(x[j])\nfor i in range(H):\n flag=0\n for j in range(W):\n if a[i][j]==WH:\n flag=flag+1\n else:\n flag=flag-1\n if flag==W:\n num.append(i)\n numnum=numnum+1\nfor i in range(numnum):\n a.pop(num[i])\nH=H-numnum\na_n=np.array(a)\ntr=a_n.T\nnum=[]\nnumnum=0\nfor i in range(W):\n flag=0\n for j in range(H):\n if tr[i][j]==WH:\n flag=flag+1\n else:\n flag=flag-1\n if flag==H:\n num.append(i)\n numnum=numnum+1\nfor i in range(numnum):\n a=np.delete(tr,num[i],0)\na_n=np.array(a)\na=a_n.T\nfor i in range(H):\n ans=''\n for j in range(W):\n ans=ans+a[i][j]\n print(ans)", "import numpy as np\nWH='.'\nBK='#'\nx=input()\nx=x.split()\nH=int(x[0])\nW=int(x[1])\na=[[] for i in range(H)]\nnum=[]\nnumnum=0\nfor i in range(H):\n x=input()\n for j in range(W):\n a[i].append(x[j])\nfor i in range(H):\n flag=0\n for j in range(W):\n if a[i][j]==WH:\n flag=flag+1\n else:\n flag=flag-1\n if flag==W:\n num.append(i)\n numnum=numnum+1\nfor i in range(numnum):\n a.pop(num[i]-i)\nH=H-numnum\na_n=np.array(a)\ntr=a_n.T\na=tr.tolist()\nnum=[]\nnumnum=0\nnum_num=0\nfor i in range(W):\n flag=0\n for j in range(H):\n if a[i][j]==WH:\n flag=flag+1\n else:\n flag=flag-1\n if flag==H:\n num.append(i)\n numnum=numnum+1\n flag=0\n else:\n flag=0\nfor i in range(numnum):\n a.pop(num[i]-i)\nW=W-numnum\na_n=np.array(a)\na=a_n.T\nfor i in range(H):\n ans=''\n for j in range(W):\n ans=ans+a[i][j]\n print(ans)"] | ['Runtime Error', 'Runtime Error', 'Runtime Error', 'Accepted'] | ['s163449458', 's387923536', 's860013125', 's651189674'] | [12516.0, 12516.0, 12508.0, 12512.0] | [160.0, 159.0, 166.0, 167.0] | [766, 807, 867, 934] |
p03273 | u999503965 | 2,000 | 1,048,576 | There is a grid of squares with H horizontal rows and W vertical columns. The square at the i-th row from the top and the j-th column from the left is represented as (i, j). Each square is black or white. The color of the square is given as an H-by-W matrix (a_{i, j}). If a_{i, j} is `.`, the square (i, j) is white; if a_{i, j} is `#`, the square (i, j) is black. Snuke is compressing this grid. He will do so by repeatedly performing the following operation while there is a row or column that consists only of white squares: * Operation: choose any one row or column that consists only of white squares, remove it and delete the space between the rows or columns. It can be shown that the final state of the grid is uniquely determined regardless of what row or column is chosen in each operation. Find the final state of the grid. | ['h,w=map(int,input().split())\nlis=[list(input()) for i in range(h)]\n\nfin=[]\n\nfor l in lis:\n if l.count(".") != w:\n fin.append(l)\n else: \n h=h-1\n\nnum=[]\nfor i in range(w):\n cnt=0\n for f in fin:\n if f[i] == ".":\n cnt+=1\n if cnt == h:\n num.append(i)\n \nfor i in num:\n for f in fin:\n f.pop(i)\n \nfor i in fin:\n print(*i)', 'h,w=map(int,input().split())\nlis=[list(input()) for i in range(h)]\n\nfin=[]\nans=[]\n\nfor l in lis:\n if l.count(".") != w:\n fin.append(l)\n else: \n h=h-1\n\ntr = []\nfor i in range(w):\n tr_row = []\n for vector in fin:\n tr_row.append(vector[i])\n tr.append(tr_row)\n \nfor t in tr:\n if t.count(".") != h:\n ans.append(t)\n else: \n w=w-1\n \nfor i in range(w):\n tr_row = []\n for vector in ans:\n tr_row.append(vector[i])\n print(*tr_row)\n', 'h,w=map(int,input().split())\nlis=[list(input()) for i in range(h)]\n\nfin=[]\nnum=[0]*w\n\nfor l in lis:\n if l.count(".") != w:\n fin.append(l)\n for i in range(w):\n if l[i]==".":\n num[i]+=1\n\nfor f in fin:\n ans=[]\n for i in range(len(num)):\n if num[i]!=h:\n ans.append(f[i])\n print(*ans,sep=\'\')\n '] | ['Runtime Error', 'Runtime Error', 'Accepted'] | ['s212378711', 's606743446', 's350717961'] | [9212.0, 9236.0, 9180.0] | [26.0, 31.0, 36.0] | [349, 476, 315] |
p03274 | u020604402 | 2,000 | 1,048,576 | There are N candles placed on a number line. The i-th candle from the left is placed on coordinate x_i. Here, x_1 < x_2 < ... < x_N holds. Initially, no candles are burning. Snuke decides to light K of the N candles. Now, he is at coordinate 0. He can move left and right along the line with speed 1. He can also light a candle when he is at the same position as the candle, in negligible time. Find the minimum time required to light K candles. | ['N,K = map(int,input().split())\nL = list(map(int,input().split()))\nLplus = list(filter(lambda x: x>=0, L))\nLminus = list(filter(lambda x: x<0 ,L))[::-1]\nans_table = []\n#print(L)\n#right_only\nif len(Lplus) >= K:\n ans_table.append(Lplus[K-1])\n#left_only\nif len(Lminus) >= K:\n ans_table.append(Lminus[K-1])\n#once_turn_right_to_left\nfor i in range(len(Lplus)-1):\n if i > K: break\n remain = K - i\n tmp = abs(Lplus[i-1])\n if remain <= len(Lminus):\n tmp += abs(Lplus[i-1] - Lminus[K-i-1])\n ans_table.append(tmp)\n#once_turn_left_to_right\nLplus,Lminus = Lminus,Lplus\nfor i in range(len(Lplus)-1):\n if i > K: break\n remain = K - i\n tmp = abs(Lplus[i-1])\n if K - i <= len(Lminus):\n \n tmp += abs(Lplus[i-1] - Lminus[K-i-1])\n ans_table.append(tmp)\n\n#print(ans_table)\nprint(min(ans_table))\n\n', 'N, K = map(int,input().split())\nL =list(map(int,input().split()))\nLzero = list(filter(lambda x:x==0,L))\nLright = list(filter(lambda x:x>0,L))\nLleft = list(map(lambda x:abs(x),filter(lambda x:x<0,L)))[::-1]\nK -= len(Lzero)\nif K <= 0:\n print(0)\n quit()\n\ndis = []\nif len(Lright) == 0:\n print(Lleft[K-1])\n quit()\nif len(Lleft) == 0:\n print(Lright[K-1])\n quit()\ndis.append(Lright[K-1])\ndis.append(Lleft[K-1])\n\n\nfor i in range(len(Lright)):\n remain = K\n if i+1 >K:\n break\n elif i+1 == K:\n dis.append(Lright[i])\n break\n d = 2*Lright[i]\n remain -= (i+1)\n d += Lleft[remain-1]\n dis.append(d)\nfor i in range(len(Lleft)):\n remain = K\n if i+1 >K:\n break\n elif i+1 == K:\n dis.append(Lleft[i])\n break\n d = 2*Lleft[i]\n remain -= (i+1)\n d += Lright[remain-1]\n dis.append(d)\nprint(min(dis))\n', 'N, K = map(int, input().split())\nL = list(map(int, input().split()))\nL.append(0)\nL.sort()\ndis = []\nfor i in range(N-K+1):\n if 0 in L[i:i+K+1]:\n l = L[i:i+K+1]\n print(l)\n d = abs(l[0]) + abs(l[-1])*2\n dis.append(d)\n d = abs(l[0])*2 + abs(l[-1])\n dis.append(d)\nprint(min(dis))\n', 'N, K = map(int,input().split())\nL =list(map(int,input().split()))\nLzero = list(filter(lambda x:x==0,L))\nLright = list(filter(lambda x:x>0,L))\nLleft = list(map(lambda x:abs(x),filter(lambda x:x<0,L)))[::-1]\nK -= len(Lzero)\nif K <= 0:\n print(0)\n quit()\n\ndis = []\nif len(Lright) == 0:\n print(Lleft[K-1])\n quit()\nif len(Lleft) == 0:\n print(Lright[K-1])\n quit()\ntry :\n dis.append(Lright[K-1])\n dis.append(Lleft[K-1])\nexcept:\n pass\n\n\nfor i in range(len(Lright)):\n remain = K\n if i+1 >K:\n break\n elif i+1 == K:\n dis.append(Lright[i])\n break\n d = 2*Lright[i]\n remain -= (i+1)\n try :\n d += Lleft[remain-1]\n dis.append(d)\n except:\n pass\nfor i in range(len(Lleft)):\n remain = K\n if i+1 >K:\n break\n elif i+1 == K:\n dis.append(Lleft[i])\n break\n d = 2*Lleft[i]\n remain -= (i+1)\n try:\n d += Lright[remain-1]\n dis.append(d)\n except:\n pass\nprint(min(dis))\n'] | ['Runtime Error', 'Runtime Error', 'Runtime Error', 'Accepted'] | ['s331100691', 's639556979', 's726044043', 's347245213'] | [14252.0, 14884.0, 141304.0, 14252.0] | [152.0, 86.0, 2104.0, 165.0] | [874, 877, 322, 993] |
p03274 | u033606236 | 2,000 | 1,048,576 | There are N candles placed on a number line. The i-th candle from the left is placed on coordinate x_i. Here, x_1 < x_2 < ... < x_N holds. Initially, no candles are burning. Snuke decides to light K of the N candles. Now, he is at coordinate 0. He can move left and right along the line with speed 1. He can also light a candle when he is at the same position as the candle, in negligible time. Find the minimum time required to light K candles. | ['N, K = map(int, input().split())\nary = [0] + list(map(int, input().split()))\nary = sorted(ary)\na = ary.index(0)\nans = float("Inf")\nfor i in range(N + 1):\n if i == a: continue\n\n k = abs(i - a)\n d = abs(ary[i])\n if k >= K and ans > d:\n ans = d\n if i < a:\n k = K - abs(i - a)\n d = abs(ary[i])\n print(k,d)\n if k > 0 and len(ary[a:]) > k:\n d += abs(ary[i] - ary[k + a])\n if ans > d:\n ans = d\n\nprint(0 if ans == float("Inf") else ans)\n', 'N, K = map(int, input().split())\nary = list(map(int, input().split()))\nary2 = sorted(ary+[0])\nzero = ary2.index(0)\nk = [abs(i - zero) if i < zero else ((i + 1) - zero)for i in range(N)]\nans = float("Inf")\nfor i in range(N - K + 1):\n if k[i] <= K:\n if ans > abs(ary[i]) + abs(ary[i] - ary[i + (K - 1)]):\n ans = abs(ary[i]) + abs(ary[i] - ary[i + (K - 1)])\nfor i in range(N-1, K-2, -1):\n if k[i] <= K:\n if ans > abs(ary[i]) + abs(ary[i] - ary[i - (K-1)]):\n ans = abs(ary[i]) + abs(ary[i] - ary[i - (K-1)])\nprint(ans)\n'] | ['Wrong Answer', 'Accepted'] | ['s607874280', 's875965129'] | [14480.0, 14568.0] | [2104.0, 122.0] | [516, 557] |
p03274 | u036340997 | 2,000 | 1,048,576 | There are N candles placed on a number line. The i-th candle from the left is placed on coordinate x_i. Here, x_1 < x_2 < ... < x_N holds. Initially, no candles are burning. Snuke decides to light K of the N candles. Now, he is at coordinate 0. He can move left and right along the line with speed 1. He can also light a candle when he is at the same position as the candle, in negligible time. Find the minimum time required to light K candles. | ['n, k = map(int, input().split())\nx = list(map(int, input().split()))\n\nans = 0\nfor i in range(n):\n d = x[i+k-1] - x[i] + min(abs(x[i]), abs(x[i+k-1]))\n ans = min(ans, d)\n \nprint(ans)', 'n,k=map(int,input().split())\nx=list(map(int,input().split()))\na=10**9\nfor i in range(n-k+1):\n d=x[i+k-1]-x[i]+min(abs(x[i]),abs(x[i+k-1]))\n a=min(a,d)\nprint(a)\n'] | ['Runtime Error', 'Accepted'] | ['s185311025', 's275421115'] | [14252.0, 14384.0] | [94.0, 89.0] | [184, 162] |
p03274 | u052499405 | 2,000 | 1,048,576 | There are N candles placed on a number line. The i-th candle from the left is placed on coordinate x_i. Here, x_1 < x_2 < ... < x_N holds. Initially, no candles are burning. Snuke decides to light K of the N candles. Now, he is at coordinate 0. He can move left and right along the line with speed 1. He can also light a candle when he is at the same position as the candle, in negligible time. Find the minimum time required to light K candles. | ['import bisect\nn, k = [int(item) for item in input().split()]\nx = [int(item) for item in input().split()]\n\nlft_num = bisect.bisect(x, 0)\nrgt_num = n - lft_num\n\nprint(rgt_num, lft_num)\nans = 10**10\nfor i in range(min(rgt_num, k)):\n r = x[lft_num + i]\n distance = abs(r)\n if i+1 == k: \n ans = min(ans, distance)\n continue\n if lft_num - (k-i-1) > 0:\n l = x[lft_num - (k-i-1)]\n distance += abs(r - l)\n ans = min(ans, distance)\nfor i in range(min(lft_num, k)):\n l = x[lft_num - i - 1]\n distance = abs(l)\n if i+1 == k: \n ans = min(ans, distance)\n continue\n if rgt_num - (k-i-1) > 0:\n r = x[lft_num + rgt_num - (k-i-1)]\n distance += abs(r - l)\n ans = min(ans, distance)\n \nprint(ans)', 'import bisect\nn, k = [int(item) for item in input().split()]\nx = [int(item) for item in input().split()]\n\nlft_num = bisect.bisect(x, 0)\nrgt_num = n - lft_num\n\nans = 10**10\nfor i in range(min(rgt_num, k)):\n r = x[lft_num + i]\n distance = abs(r)\n if i+1 == k: \n ans = min(ans, distance)\n continue\n if lft_num - (k-i-1) >= 0:\n l = x[lft_num - (k-i-1)]\n distance += abs(r - l)\n ans = min(ans, distance)\nfor i in range(min(lft_num, k)):\n l = x[lft_num - i - 1]\n distance = abs(l)\n if i+1 == k: \n ans = min(ans, distance)\n continue\n if lft_num + (k-i) < n:\n r = x[lft_num + (k-i)]\n distance += abs(r - l)\n ans = min(ans, distance)\n \nprint(ans)', 'import bisect\nn, k = [int(item) for item in input().split()]\nx = [int(item) for item in input().split()]\n\nlft_num = bisect.bisect(x, 0)\nrgt_num = n - lft_num\n\nans = 10**10\nfor i in range(min(rgt_num, k)):\n r = x[lft_num + i]\n distance = abs(r)\n if i+1 == k: \n ans = min(ans, distance)\n continue\n if lft_num - (k-i-1) >= 0:\n l = x[lft_num - (k-i-1)]\n distance += abs(r - l)\n ans = min(ans, distance)\nfor i in range(min(lft_num, k)):\n l = x[lft_num - i - 1]\n distance = abs(l)\n if i+1 == k: \n ans = min(ans, distance)\n continue\n if lft_num + (k-i-2) < n:\n r = x[lft_num + (k-i-2)]\n distance += abs(r - l)\n ans = min(ans, distance)\n \nprint(ans)'] | ['Wrong Answer', 'Wrong Answer', 'Accepted'] | ['s073831632', 's293056494', 's929175526'] | [14384.0, 14480.0, 14096.0] | [148.0, 145.0, 148.0] | [771, 734, 738] |
p03274 | u059210959 | 2,000 | 1,048,576 | There are N candles placed on a number line. The i-th candle from the left is placed on coordinate x_i. Here, x_1 < x_2 < ... < x_N holds. Initially, no candles are burning. Snuke decides to light K of the N candles. Now, he is at coordinate 0. He can move left and right along the line with speed 1. He can also light a candle when he is at the same position as the candle, in negligible time. Find the minimum time required to light K candles. | ['# encoding utf-8\n\nN, K = map(int, input().split())\n\nx = list(int(i) for i in input().split())\n\n\nfor i in range(N):\n if 0 <= x[i]:\n border = i\n break\n\nlen_run = 100000\n\nif border == 0:\n len_run = min(abs(x[K-1]), len_run)\n\nif border == N-1:\n len_run = min(abs(x[N-K]), len_run)\n\nfor i in range(K):\n if border-K+i >= 0 and border+i <= N:\n len_run = min(abs(2*x[border-K+i])+abs(x[border+i-1]), len_run)\n len_run = min(abs(x[border-K+i])+abs(2*x[border+i-1]), len_run)\n\nprint(len_run)\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n# y.sort()\n# max = y[K-1]\n# if max in x_pos:\n\n\n\n# else:\n/2\n\n\n\n#\n#\n\n\n\n# for j in range(len(x_neg)):\n\n\n\n\n# max = -z[K-1]\n# if max in x_neg:\n\n\n\n# else:\n/2\n\n\n\n#\n\n\n# elif len(x_pos) == 0:\n# x.sort().reverse()\n\n# else:\n\n\n#\n\n', '#encoding utf 8\n\nn, k = map(int, input().split())\n\npos = list(int(i) for i in input().split())\n\nans = abs(pos[0])+abs(pos[0]-pos[k-1])\n\nfor i in range(n-k+1):\n val = 0\n val += abs(pos[i] - pos[i+k-1])\n val += min(abs(pos[i]), abs(pos[i+k-1]))\n\n if val < ans:\n ans = val\nprint(ans)\n'] | ['Runtime Error', 'Accepted'] | ['s578767327', 's384674975'] | [14564.0, 14568.0] | [126.0, 98.0] | [1683, 300] |
p03274 | u059262067 | 2,000 | 1,048,576 | There are N candles placed on a number line. The i-th candle from the left is placed on coordinate x_i. Here, x_1 < x_2 < ... < x_N holds. Initially, no candles are burning. Snuke decides to light K of the N candles. Now, he is at coordinate 0. He can move left and right along the line with speed 1. He can also light a candle when he is at the same position as the candle, in negligible time. Find the minimum time required to light K candles. | ['import numpy as np\nb = list(map(int, input().split()))\na = list(map(int, input().split()))\nx = b[0]-b[1]+1\nres = 10**10\n \nfor i in range(x):\n tmp = i + b[1] - 1\n res = min( a[tmp]-a[i] + min(-a[i],a[tmp]),res)\n \nprint(res)', 'import numpy as np\nb = list(map(int, input().split()))\na = list(map(int, input().split()))\nx = b[0]-b[1]+1\nres = 10*100\n \nfor i in range(x):\n tmp = i + b[1] - 1\n res = min( a[tmp]-a[i] + min(-a[i],a[tmp]),res) \n\nprint(res)', 'import numpy as np\nb = list(map(int, input().split()))\na = list(map(int, input().split()))\nx = b[0]-b[1]+1\nres = 10**15\n \nfor i in range(x):\n tmp = i + b[1] - 1\n res = min( a[tmp]-a[i] + min(-a[i],a[tmp]),res)\n \nprint(res)', 'b = list(map(int, input().split()))\na = list(map(int, input().split()))\nx = b[0]-b[1]+1\nres = 10**15\n \nfor i in range(x):\n tmp = i + b[1] - 1\n if res > (a[tmp]-a[i] + min(abs(a[i]),abs(a[tmp]))):\n\t res = a[tmp]-a[i] + min(abs(a[i]),abs(a[tmp]))\n \nprint(res)'] | ['Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Accepted'] | ['s122931656', 's175159276', 's253599882', 's282245627'] | [23080.0, 23084.0, 23052.0, 14224.0] | [211.0, 335.0, 380.0, 103.0] | [235, 235, 235, 273] |
p03274 | u070561949 | 2,000 | 1,048,576 | There are N candles placed on a number line. The i-th candle from the left is placed on coordinate x_i. Here, x_1 < x_2 < ... < x_N holds. Initially, no candles are burning. Snuke decides to light K of the N candles. Now, he is at coordinate 0. He can move left and right along the line with speed 1. He can also light a candle when he is at the same position as the candle, in negligible time. Find the minimum time required to light K candles. | ['n = int(input())\nb = list(map(int,input().split()))\n\n#b = list(set(a))\nb.sort()\nprint(b)\n \nif len(b) > 1:\n l = len(b)//2\n print(b[l])\nelse:\n print(b[0])\n ', 'n,k = map(int,input().split())\n\nx = list(map(int,input().split()))\n\nx.append(0)\nx.sort()\n\nmin = 10**8\n\nzeroIdx = x.index(0)\n\n\nif zeroIdx + k < len(x) :\n min = x[zeroIdx + k] \n\n# minus \nif zeroIdx - k >= 0 :\n tmp = abs(x[zeroIdx + k])\n if tmp < min :\n min = tmp\n\n/minus\nplsIdx = k+1\nmisIdx = k-1\nwhile True:\n p = 0\n m = 0\n if plsIdx + 1 < len(x):\n p = abs(x[plsIdx])\n\n if misIdx - 1 >= len(x):\n m = abs(x[plsIdx])\n \n if p == 0 :\n misIdx -= 1\n elif m == 0 :\n plsIdx += 1\n elif p < m :\n plsIdx += 1\n else: \n misIdx -= 1\n\n if plsIdx - misIdx >= k :\n if abs(x[plsIdx]) > abs(x[misIdx]) :\n tmp = abs(x[plsIdx]) + (abs(x[misIdx])<<1)\n else:\n tmp = (abs(x[plsIdx])<<1) + abs(x[misIdx])\n break\n\nif tmp < min :\n min = tmp\nprint(min)', 'n,k = map(int,input().split())\n\nx = list(map(int,input().split()))\n\nx.append(0)\nx.sort()\n\nmin = 10**8\n\nzeroIdx = x.index(0)\n\n\nif zeroIdx + k < len(x) :\n min = x[zeroIdx + k] \n\n# minus \nif zeroIdx - k >= 0 :\n tmp = abs(x[zeroIdx - k])\n if tmp < min :\n min = tmp\n\n/minus\nplsIdx = k+1\nmisIdx = k-1\nwhile True:\n p = 0\n m = 0\n if plsIdx + 1 < len(x):\n p = abs(x[plsIdx])\n\n if misIdx - 1 >= 0:\n m = abs(x[misIdx])\n \n if p == 0 :\n misIdx -= 1\n elif m == 0 :\n plsIdx += 1\n elif p < m :\n plsIdx += 1\n else: \n misIdx -= 1\n\n if plsIdx - misIdx >= k :\n if abs(x[plsIdx]) > abs(x[misIdx]) :\n tmp = abs(x[plsIdx]) + (abs(x[misIdx])<<1)\n else:\n tmp = (abs(x[plsIdx])<<1) + abs(x[misIdx])\n break\n\nif tmp < min :\n min = tmp\nprint(min)', 'n,k = map(int,input().split())\n\nx = list(map(int,input().split()))\n\nx.append(0)\nx.sort()\n\nmin = 10**8\n\nzeroIdx = x.index(0)\n\n\nif zeroIdx + k < len(x) :\n min = x[zeroIdx + k] \n\n# minus \nif zeroIdx - k >= 0 :\n tmp = abs(x[zeroIdx + k])\n if tmp < min :\n min = tmp\n\n/minus\nplsIdx = k+1\nmisIdx = k-1\nwhile True:\n p = 0\n m = 0\n if plsIdx + 1 < len(x):\n p = abs(x[plsIdx])\n\n if misIdx - 1 >= 0:\n m = abs(x[plsIdx])\n \n if p == 0 :\n misIdx -= 1\n elif m == 0 :\n plsIdx += 1\n elif p < m :\n plsIdx += 1\n else: \n misIdx -= 1\n\n if plsIdx - misIdx >= k :\n if abs(x[plsIdx]) > abs(x[misIdx]) :\n tmp = abs(x[plsIdx]) + (abs(x[misIdx])<<1)\n else:\n tmp = (abs(x[plsIdx])<<1) + abs(x[misIdx])\n break\n\nif tmp < min :\n min = tmp\nprint(min)', 'n,k = map(int,input().split())\n\nx = list(map(int,input().split()))\n\nx.append(0)\nx.sort()\n\nmin = 10**8\n\nzeroIdx = x.index(0)\n\n\nif zeroIdx + k < len(x) :\n min = x[zeroIdx + k] \n\n# minus \nif zeroIdx - k >= 0 :\n tmp = abs(x[zeroIdx - k])\n if tmp < min :\n min = tmp\n\n/minus\nplsIdx = k+1\nmisIdx = k-1\nwhile True:\n p = 0\n m = 0\n if plsIdx + 1 < len(x):\n p = abs(x[plsIdx])\n\n if misIdx - 1 >= 0:\n m = abs(x[plsIdx])\n \n if p == 0 :\n misIdx -= 1\n elif m == 0 :\n plsIdx += 1\n elif p < m :\n plsIdx += 1\n else: \n misIdx -= 1\n\n if plsIdx - misIdx >= k :\n if abs(x[plsIdx]) > abs(x[misIdx]) :\n tmp = abs(x[plsIdx]) + (abs(x[misIdx])<<1)\n else:\n tmp = (abs(x[plsIdx])<<1) + abs(x[misIdx])\n break\n\nif tmp < min :\n min = tmp\nprint(min)', 'n = int(input())\nb = list(map(int,input().split()))\n\n#b = list(set(a))\nb.sort()\n \nif len(b) > 1:\n l = len(b)//2\n print(b[l])\nelse:\n print(b[0])\n ', 'n,k = map(int,input().split())\nx = list(map(int,input().split()))\n\nx.append(0)\nx.sort()\n\n#print(x)\n\nmin = 10**10\n\nzeroIdx = x.index(0)\n\nfor i in range(zeroIdx-k,zeroIdx+1):\n if i < 0 : \n continue\n elif len(x) <= i + k :\n break\n\n plsIdx = i + k \n misIdx = i\n\n #print(misIdx,plsIdx,x[misIdx],x[plsIdx])\n\n if abs(x[plsIdx]) > abs(x[misIdx]) :\n tmp = abs(x[plsIdx]) + (abs(x[misIdx])<<1)\n else:\n tmp = (abs(x[plsIdx])<<1) + abs(x[misIdx])\n\n if tmp < min :\n min = tmp\n\nprint(min)'] | ['Runtime Error', 'Runtime Error', 'Runtime Error', 'Runtime Error', 'Runtime Error', 'Runtime Error', 'Accepted'] | ['s127208683', 's168203220', 's369971917', 's499927238', 's749940779', 's837572078', 's813888742'] | [2940.0, 14252.0, 14252.0, 14224.0, 14484.0, 3060.0, 14844.0] | [17.0, 96.0, 104.0, 94.0, 96.0, 17.0, 84.0] | [170, 914, 909, 909, 909, 161, 533] |
p03274 | u076917070 | 2,000 | 1,048,576 | There are N candles placed on a number line. The i-th candle from the left is placed on coordinate x_i. Here, x_1 < x_2 < ... < x_N holds. Initially, no candles are burning. Snuke decides to light K of the N candles. Now, he is at coordinate 0. He can move left and right along the line with speed 1. He can also light a candle when he is at the same position as the candle, in negligible time. Find the minimum time required to light K candles. | ['import sys\ninput=sys.stdin.readline\n\ninput = open(sys.argv[1],"r").readline\n\ndef main():\n N,K = map(int, input().split())\n X = list(map(int, input().split()))\n ans = 3*10**8\n for i in range(0,N-K+1):\n l = X[i]\n r = X[i+K-1]\n if l*r < 0:\n ans = min(ans, 2*min(abs(l),abs(r)) + max(abs(l),abs(r)))\n else:\n ans = min(ans, max(abs(l),abs(r)))\n\n print(ans)\n\nif __name__ == \'__main__\':\n main()\n', "import sys\ninput=sys.stdin.readline\n\ndef main():\n N,K = map(int, input().split())\n X = list(map(int, input().split()))\n ans = 3*10**8\n for i in range(0,N-K+1):\n l = X[i]\n r = X[i+K-1]\n if l*r < 0:\n ans = min(ans, 2*min(abs(l),abs(r)) + max(abs(l),abs(r)))\n else:\n ans = min(ans, max(abs(l),abs(r)))\n\n print(ans)\n\nif __name__ == '__main__':\n main()\n"] | ['Runtime Error', 'Accepted'] | ['s955387390', 's823259858'] | [3064.0, 14596.0] | [17.0, 83.0] | [456, 416] |
p03274 | u077291787 | 2,000 | 1,048,576 | There are N candles placed on a number line. The i-th candle from the left is placed on coordinate x_i. Here, x_1 < x_2 < ... < x_N holds. Initially, no candles are burning. Snuke decides to light K of the N candles. Now, he is at coordinate 0. He can move left and right along the line with speed 1. He can also light a candle when he is at the same position as the candle, in negligible time. Find the minimum time required to light K candles. | ['\ndef main():\n N, K, *X = map(int, open(0).read().split())\n ans = float("inf")\n for l, r in zip(X, X[k - 1 :]):\n ans = min(ans, r - l + min(abs(l), abs(r)))\n print(ans)\n\n\nif __name__ == "__main__":\n main()', '\ndef main():\n N, K, *X = map(int, open(0).read().split())\n cand = [r - l + min(abs(l), abs(r)) for l, r in zip(X, X[K - 1 :])]\n ans = min(cand)\n print(ans)\n\n\nif __name__ == "__main__":\n main()\n'] | ['Runtime Error', 'Accepted'] | ['s799329647', 's353011745'] | [14052.0, 14052.0] | [42.0, 59.0] | [255, 237] |
p03274 | u083960235 | 2,000 | 1,048,576 | There are N candles placed on a number line. The i-th candle from the left is placed on coordinate x_i. Here, x_1 < x_2 < ... < x_N holds. Initially, no candles are burning. Snuke decides to light K of the N candles. Now, he is at coordinate 0. He can move left and right along the line with speed 1. He can also light a candle when he is at the same position as the candle, in negligible time. Find the minimum time required to light K candles. | ["\nimport sys, re, os\nfrom collections import deque, defaultdict, Counter\nfrom math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians\nfrom itertools import permutations, combinations, product, accumulate\nfrom operator import itemgetter, mul\nfrom copy import deepcopy\nfrom string import ascii_lowercase, ascii_uppercase, digits\nfrom fractions import gcd\nfrom bisect import bisect, bisect_right, bisect_left\n\ndef input(): return sys.stdin.readline().strip()\ndef INT(): return int(input())\ndef MAP(): return map(int, input().split())\ndef S_MAP(): return map(str, input().split())\ndef LIST(): return list(map(int, input().split()))\ndef S_LIST(): return list(map(str, input().split()))\n \nsys.setrecursionlimit(10 ** 9)\nINF = float('inf')\nmod = 10 ** 9 + 7\n\nN, K = MAP()\nA = LIST()\n\nzero = A.count(0)\n# A.(0)\nl = bisect_left(A, 0)\nr = bisect(A, 0)\nzero = r - l\nC = []\nfor a in A[:l]:\n if a == 0:\n continue\n C.append(a)\n \nB = C + A[r:]\n\n\nw = K - zero\nans = INF\nB.insert(0, -INF)\nB.append(INF)\nif zero == K:\n print(0)\n exit()\n\nfor i in range(len(B) - K + 1):\n r = B[i + K - zero - 1]\n l = B[i]\n tmp = INF\n if l < 0 and r > 0:\n tmp = min(abs(l), r) + r - l\n # ans = min(ans, tmp)\n elif l > 0 and B[i-1] < 0:\n tmp = min(abs(l), r) + r - l\n\n elif r < 0 and B[i + K - zero - 1 + 1] > 0:\n tmp = min(abs(l), r) + r - l\n ans = min(ans, tmp)\nprint(ans)\n\n\n # if abs(B[i]) <= :\n\n\n\n# print(B[i])\n# ans = min(ans, tmp)\n# print(ans)", "\nimport sys, re, os\nfrom collections import deque, defaultdict, Counter\nfrom math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians\nfrom itertools import permutations, combinations, product, accumulate\nfrom operator import itemgetter, mul\nfrom copy import deepcopy\nfrom string import ascii_lowercase, ascii_uppercase, digits\nfrom fractions import gcd\nfrom bisect import bisect, bisect_right, bisect_left\n\ndef input(): return sys.stdin.readline().strip()\ndef INT(): return int(input())\ndef MAP(): return map(int, input().split())\ndef S_MAP(): return map(str, input().split())\ndef LIST(): return list(map(int, input().split()))\ndef S_LIST(): return list(map(str, input().split()))\n \nsys.setrecursionlimit(10 ** 9)\nINF = float('inf')\nmod = 10 ** 9 + 7\n\nN, K = MAP()\nA = LIST()\n\nzero = A.count(0)\n# A.(0)\nl = bisect_left(A, 0)\nr = bisect(A, 0)\nzero = r - l\nC = []\nfor a in A[:l]:\n if a == 0:\n continue\n C.append(a)\n \nB = C + A[r:]\n\n\nw = K - zero\nans = INF\nB.insert(0, -INF)\nB.append(INF)\nif zero == K:\n print(0)\n exit()\n\nfor i in range(len(B) - K + 1):\n r = B[i + K - zero - 1]\n l = B[i]\n tmp = INF\n if l < 0 and r > 0:\n tmp = min(abs(l), r) + r - l\n # ans = min(ans, tmp)\n elif l > 0 and B[i-1] < 0:\n tmp = min(abs(l), r) + r - l\n\n elif r < 0 and B[i + K - zero - 1 + 1] < 0:\n tmp = min(abs(l), r) + r - l\n ans = min(ans, tmp)\nprint(ans)\n\n\n # if abs(B[i]) <= :\n\n\n\n# print(B[i])\n# ans = min(ans, tmp)\n# print(ans)", "import sys, re, os\nfrom collections import deque, defaultdict, Counter\nfrom math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians\nfrom itertools import permutations, combinations, product, accumulate\nfrom operator import itemgetter, mul\nfrom copy import deepcopy\nfrom string import ascii_lowercase, ascii_uppercase, digits\nfrom fractions import gcd\n \ndef input(): return sys.stdin.readline().strip()\ndef INT(): return int(input())\ndef MAP(): return map(int, input().split())\ndef S_MAP(): return map(str, input().split())\ndef LIST(): return list(map(int, input().split()))\ndef S_LIST(): return list(map(str, input().split()))\n \nsys.setrecursionlimit(10 ** 9)\nINF = float('inf')\nmod = 10 ** 9 + 7\n\nN, K = MAP()\nX = LIST()\n\n# dist = 0\ns = []\nl = []\ns = deque(s)\nl = deque(l)\nfor x in X:\n if x < 0:\n s.appendleft(-1 * x)\n else:\n l.append(x)\n# s.sort()\n# print(s, l)\n\nleft = 0\nright = 0\nq = []\nwhile len(q) != K:\n if len(s) != 0 and len(l) != 0:\n if s[0] <= l[0]:\n left = s[0]\n q.append(s.popleft())\n else:\n right = l[0]\n q.append(l.popleft())\n elif len(s) == 0 and len(l) != 0:\n right = l.popleft()\n q.append(right)\n else:\n left = s.popleft()\n q.append(left)\n\nprint(min(left, right) + left + right)\n\n\n\n", "import sys, re, os\nfrom collections import deque, defaultdict, Counter\nfrom math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians\nfrom itertools import permutations, combinations, product, accumulate\nfrom operator import itemgetter, mul\nfrom copy import deepcopy\nfrom string import ascii_lowercase, ascii_uppercase, digits\nfrom fractions import gcd\n \ndef input(): return sys.stdin.readline().strip()\ndef INT(): return int(input())\ndef MAP(): return map(int, input().split())\ndef S_MAP(): return map(str, input().split())\ndef LIST(): return list(map(int, input().split()))\ndef S_LIST(): return list(map(str, input().split()))\n \nsys.setrecursionlimit(10 ** 9)\nINF = float('inf')\nmod = 10 ** 9 + 7\n\nN, K = MAP()\nX = LIST()\n\n# dist = 0\ns = []\nl = []\ns = deque(s)\nl = deque(l)\nfor x in X:\n if x < 0:\n s.appendleft(-1 * x)\n else:\n l.append(x)\n# s.sort()\n# print(s, l)\n\nleft = 0\nright = 0\nq = []\nwhile len(q) != K:\n if len(s) != 0 and len(l) != 0:\n if s[0] <= l[0]:\n left = s[0]\n q.append(s.popleft())\n else:\n right = l[0]\n q.append(l.popleft())\n elif len(s) == 0:\n right = l.popleft()\n q.append(right)\n else:\n left = s.popleft()\n q.append(left)\n\nprint(min(left, right) + left + right)\n\n\n\n", "import sys, re, os\nfrom collections import deque, defaultdict, Counter\nfrom math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians\nfrom itertools import permutations, combinations, product, accumulate\nfrom operator import itemgetter, mul\nfrom copy import deepcopy\nfrom string import ascii_lowercase, ascii_uppercase, digits\nfrom heapq import heapify, heappop, heappush\n \ndef input(): return sys.stdin.readline().strip()\ndef INT(): return int(input())\ndef MAP(): return map(int, input().split())\ndef S_MAP(): return map(str, input().split())\ndef LIST(): return list(map(int, input().split()))\ndef S_LIST(): return list(map(str, input().split()))\n \nsys.setrecursionlimit(10 ** 9)\nINF = float('inf')\nmod = 10 ** 9 + 7\n\nN, K = MAP()\nX = LIST()\n\nans = INF\nfor i in range(N-K+1):\n a, b = X[i], X[i+K-1]\n # if a <= 0 and 0 < b:\n if b <= 0:\n ans = min(abs(a), ans)\n elif 0 <= a:\n ans = min(abs(b), ans)\n else:\n tmp = min(abs(a), abs(b)) + (b - a)\n ans = min(ans, tmp)\n\nprint(ans)\n"] | ['Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Accepted'] | ['s085451043', 's108839562', 's891181527', 's951993120', 's907374021'] | [16312.0, 16316.0, 16324.0, 16320.0, 15012.0] | [130.0, 150.0, 142.0, 137.0, 97.0] | [1623, 1623, 1323, 1307, 1024] |
p03274 | u085717502 | 2,000 | 1,048,576 | There are N candles placed on a number line. The i-th candle from the left is placed on coordinate x_i. Here, x_1 < x_2 < ... < x_N holds. Initially, no candles are burning. Snuke decides to light K of the N candles. Now, he is at coordinate 0. He can move left and right along the line with speed 1. He can also light a candle when he is at the same position as the candle, in negligible time. Find the minimum time required to light K candles. | ['#!/usr/bin/env python\n# coding: utf-8\n\n# In[26]:\n\n\nN,K = map(int, input().split())\nx = list(map(int, input().split()))\n\n\n# In[33]:\n\n\nans = max([abs(y) for y in x])\nfor i in range(N-K+1):\n tmp = x[i:i+K]\n ans = min(abs(tmp[0])+(tmp[K-1]-tmp[0]),abs(tmp[K-1])+(tmp[K-1]-tmp[0]))\nprint(ans)\n\n\n# In[ ]:\n\n\n\n\n', '#!/usr/bin/env python\n# coding: utf-8\n\n# In[26]:\n\n\nN,K = map(int, input().split())\nx = list(map(int, input().split()))\n\n\n# In[35]:\n\n\nans = 10**10\nfor i in range(N-K+1):\n ans = min(ans, abs(x[i])+(x[i+K-1]-x[i]),abs(x[i+K-1])+(x[i+K-1]-x[i]))\nprint(ans)\n\n\n# In[ ]:\n\n\n\n\n'] | ['Wrong Answer', 'Accepted'] | ['s684485538', 's828427949'] | [20004.0, 20072.0] | [2206.0, 86.0] | [309, 271] |
p03274 | u102126195 | 2,000 | 1,048,576 | There are N candles placed on a number line. The i-th candle from the left is placed on coordinate x_i. Here, x_1 < x_2 < ... < x_N holds. Initially, no candles are burning. Snuke decides to light K of the N candles. Now, he is at coordinate 0. He can move left and right along the line with speed 1. He can also light a candle when he is at the same position as the candle, in negligible time. Find the minimum time required to light K candles. | ['N, K = map(int, input().split())\nx = list(map(int, input().split()))\ndis = []\nfor i in range(N - K + 1):\n dis.append(abs(x[i] - x[i + K - 1]) + abs(x[i]))\n dis.append(abs(x[i] - x[i + K - 1]) + abs(x[i + k - 1]))\nprint(min(dis))\n', 'N, K = map(int, input().split())\nx = list(map(int, input().split()))\ndis = []\nfor i in range(N - K + 1):\n dis.append(abs(x[i] - x[i + K - 1]) + abs(x[i]))\n dis.append(abs(x[i] - x[i + K - 1]) + abs(x[i + K - 1]))\nprint(min(dis))\n'] | ['Runtime Error', 'Accepted'] | ['s007432395', 's710835082'] | [14252.0, 14392.0] | [42.0, 94.0] | [235, 235] |
p03274 | u102902647 | 2,000 | 1,048,576 | There are N candles placed on a number line. The i-th candle from the left is placed on coordinate x_i. Here, x_1 < x_2 < ... < x_N holds. Initially, no candles are burning. Snuke decides to light K of the N candles. Now, he is at coordinate 0. He can move left and right along the line with speed 1. He can also light a candle when he is at the same position as the candle, in negligible time. Find the minimum time required to light K candles. | ['# N, K = 9, 5\n\nN, K = map(int, input().split())\nX = [int(i) for i in input().split()]\nX_plus = []\nX_minus = []\nfor i in range(N):\n if X[i] < 0:\n X_minus.append(X[i])\n else:\n X_plus.append(X[i])\n\n# print(X_minus)\nres = []\nlen_plus = len(X_plus)\nlen_minus = len(X_minus)\nif len_minus != 0:\n for i_plus in range(len_plus):\n if K-i_plus-1 <= len_minus:\n res.append(X_plus[i_plus]*2 - X_minus[-(K-i_plus-1)])\nif len_plus >= K:\n res.append(X_plus[K-1])\n\nif len_plus != 0:\n for i_minus in range(len_minus):\n if K-i_minus <= len_plus:\n res.append(abs(-X_minus[-i_minus-1])*2 + X_plus[K-i_minus-2])\nif len_minus >= K:\n if len_plus > 0:\n if X_plus[0]==0\n res.append(-X_minus[-K+1])\n else:\n res.append(-X_minus[-K])\nprint(min(res))', '# N, K = 3, 2\n\nN, K = map(int, input().split())\nX = [int(i) for i in input().split()]\nX_plus = []\nX_minus = []\nfor i in range(N):\n if X[i] < 0:\n X_minus.append(X[i])\n else:\n X_plus.append(X[i])\n\n# print(X_minus)\n\nres = []\nlen_plus = len(X_plus)\nlen_minus = len(X_minus)\nif len_minus != 0:\n for i_plus in range(len_plus):\n if K-i_plus-1 <= len_minus:\n res.append(X_plus[i_plus]*2 - X_minus[-(K-i_plus-1)])\nif len_plus >= K:\n res.append(X_plus[K-1])\n# print(res)\n\nif len_plus != 0:\n for i_minus in range(len_minus):\n if K-i_minus-1 <= len_plus:\n res.append(abs(-X_minus[-i_minus-1])*2 + X_plus[K-i_minus-2])\n\nif len_minus >= K:\n if len_plus > 0:\n if X_plus[0]==0:\n res.append(-X_minus[-K+1])\n else:\n res.append(-X_minus[-K])\n# print(res)\nprint(min(res))'] | ['Runtime Error', 'Accepted'] | ['s242360674', 's078265320'] | [3064.0, 14228.0] | [17.0, 118.0] | [886, 904] |
p03274 | u103730790 | 2,000 | 1,048,576 | There are N candles placed on a number line. The i-th candle from the left is placed on coordinate x_i. Here, x_1 < x_2 < ... < x_N holds. Initially, no candles are burning. Snuke decides to light K of the N candles. Now, he is at coordinate 0. He can move left and right along the line with speed 1. He can also light a candle when he is at the same position as the candle, in negligible time. Find the minimum time required to light K candles. | ['n, k = map(int,input().split())\nx = list(map(int,input().split()))\ntime = 10**9\n\nfor i in range(n - k + 1):\n x_k = [ x[i], x_k[i+k-1] ]\n #print(x_k)\n \n if x_k[0] >= 0:\n t = x_k[1]\n \n elif x_k[1] <= 0:\n t = -x_k[0]\n \n else:\n t = min(-x_k[0] + x_k[1] *2,-x_k[0] * 2 + x_k[1])\n\n time = min(t, time)\n \nprint(time)\n', 'n, k = map(int,input().split())\nx = list(map(int,input().split()))\ntime = 10**9\nx_k = [0, 0]\nfor i in range(n - k + 1):\n x_k[0] = x[i] \n x_k[1] = x[i+k-1] \n #print(x_k)\n \n if x_k[0] >= 0:\n t = x_k[1]\n \n elif x_k[1] <= 0:\n t = -x_k[0]\n \n else:\n t = min(-x_k[0] + x_k[1] *2,-x_k[0] * 2 + x_k[1])\n\n time = min(t, time)\n \nprint(time)\n'] | ['Runtime Error', 'Accepted'] | ['s538970166', 's064533962'] | [14224.0, 14224.0] | [42.0, 97.0] | [369, 394] |
p03274 | u111365362 | 2,000 | 1,048,576 | There are N candles placed on a number line. The i-th candle from the left is placed on coordinate x_i. Here, x_1 < x_2 < ... < x_N holds. Initially, no candles are burning. Snuke decides to light K of the N candles. Now, he is at coordinate 0. He can move left and right along the line with speed 1. He can also light a candle when he is at the same position as the candle, in negligible time. Find the minimum time required to light K candles. | ["X,Y = map(int,input().split())\nwhole = []\nfor i in range(X):\n now = input()\n if now == '.' * Y:\n pass\n else:\n add = []\n for i in range(Y):\n if now[i] == '.':\n add.append(0)\n else:\n add.append(1)\n whole.append(add)\nj = 0\nwhile j < len(whole[0]):\n for i in range(len(whole)):\n if whole[i][j] == 1:\n j += 1\n break\n else:\n for i in range(len(whole)):\n del whole[i][j]\nfor i in range(len(whole)):\n now = whole[i]\n ans = ''\n for j in range(len(now)):\n if now[j] == 0:\n ans += '.'\n else:\n ans += '#'\n print(ans)", 'n,k = map(int,input().split())\nx = list(map(int,input().split()))\nproto = []\nfor i in range(n-k+1):\n left = x[i]\n right = x[i+k-1]\n al = abs(left)\n ar = abs(right)\n if left * right < 0:\n now = al + ar + min(al,ar)\n else:\n now = max(al,ar)\n proto.append(now)\nprint(min(proto))'] | ['Runtime Error', 'Accepted'] | ['s867714979', 's325607393'] | [5452.0, 14224.0] | [35.0, 93.0] | [586, 288] |
p03274 | u117348081 | 2,000 | 1,048,576 | There are N candles placed on a number line. The i-th candle from the left is placed on coordinate x_i. Here, x_1 < x_2 < ... < x_N holds. Initially, no candles are burning. Snuke decides to light K of the N candles. Now, he is at coordinate 0. He can move left and right along the line with speed 1. He can also light a candle when he is at the same position as the candle, in negligible time. Find the minimum time required to light K candles. | ['INF = 1e9\nn,k = map(int, input().split())\nx = list(map(int, input().split()))\nans = INF\nfor i in range(n-k):\n if x[i]*x[i+k-1]<0:\n a = abs(x[i])+x[i+k-1] + min(abs(x[i], x[i+k-1]))\n else:\n a = abs(x[i+k-1])\n \n ans = min(ans, a)\n\nif k==1:\n ans = abs(x[0])\nprint(ans)', 'INF = 1e9\nn,k = map(int, input().split())\nx = list(map(int, input().split()))\nans = INF\nfor i in range(n-k+1):\n if x[i]*x[i+k-1]>=0:\n ans = min(ans, max(abs(x[i]), abs(x[i+k-1])))\n else:\n a = min(abs(x[i]), abs(x[i+k-1]))\n b = max(abs(x[i]), abs(x[i+k-1]))\n ans = min(ans, a*2+b)\nprint(ans)'] | ['Runtime Error', 'Accepted'] | ['s169338671', 's207751632'] | [14568.0, 14532.0] | [76.0, 114.0] | [294, 324] |
p03274 | u123756661 | 2,000 | 1,048,576 | There are N candles placed on a number line. The i-th candle from the left is placed on coordinate x_i. Here, x_1 < x_2 < ... < x_N holds. Initially, no candles are burning. Snuke decides to light K of the N candles. Now, he is at coordinate 0. He can move left and right along the line with speed 1. He can also light a candle when he is at the same position as the candle, in negligible time. Find the minimum time required to light K candles. | ['#!/usr/bin/env python3\n# -*- coding: UTF-8 -*-\n\n#WAA TLEEEEEEEEEE\nn,k=map(int,input().split())\nx=[int(i) for i in input().split()]\nl,r=[],[]\nfor i in range(n):\n if x[i]<0 and i+1<n: l.append(abs(x[i]-min(x[i+1],0)))\n elif x[i]<0: l.append(-x[i])\n if x[i]>=0 and i>0: r.append(x[i]-max(0,x[i-1]))\n elif x[i]>=0: r.append(x[i])\n\nl=l[::-1]\nl=l[:k]\nr=r[:k]\n\nll=len(l)\nrr=len(r)\n\nans=sum(l)*2+sum(r)*2\nif ll==k: ans=min(ans,sum(l))\nif rr==k: ans=min(ans,sum(r))\nlx=sum(l)*2\nrx=sum(r)*2\nfor i in range(1,k):\n if rr-i>0 and i<=ll and min(i,ll)+(rr-i)>=k:\n lx=lx-(l[-i]*2)+r[i-1]\n ans=min(ans,lx)\n if ll-i>0 and i<=rr and min(i,rr)+(ll-i)>=k:\n rx=rx-(r[-i]*2)+l[i-1]\n ans=min(ans,rx)\nprint(ans)', 'n,k=map(int,input().split())\nx=[int(i) for i in input().split()]\nl,r=[],[]\nfor i in range(n):\n if x[i]<0 and i+1<n: l.append(abs(x[i]-min(x[i+1],0)))\n elif x[i]<0: l.append(-x[i])\n if x[i]>=0 and i>0: r.append(x[i]-max(0,x[i-1]))\n elif x[i]>=0: r.append(x[i])\n\nl=l[::-1]\nl=l[:k]\nr=r[:k]\n\nll=len(l)\nrr=len(r)\nlx=sum(l)\nrx=sum(r)\n\nif ll<k: lx=lx*2+sum(r[:(k-ll)])\nif rr<k: rx=rx*2+sum(l[:(k-rr)])\nans=min(lx,rx)\nprint(ans)\no=[ll,[0,k-ll][ll<k]]\np=[rr,[0,k-rr][rr<k]]\n\n"""\n-30 -10 10 20 50\nprint(o)\nprint(p)\n[2, 1]\n[3, 0]\n"""\n\nfor i in range(1,k):\n if o[1]==0: lx*=2\n #if r[1]==0: rx*=2\n if o[1]+1<=rr and o[0]>0:\n lx-=l[o[0]-1]*2\n lx+=r[o[1]]\n o[0]-=1\n o[1]+=1\n ans=min(ans,lx)\n #if p[1]+1<=ll and p[0]>0:\n # rx-=r[p[0]-1]*2\n # rx+=l[p[1]]\n # p[0]-=1\n # p[1]+=1\n # ans=min(ans,rx)\nprint(ans)\n', 'n,k=map(int,input().split())\nx=[int(i) for i in input().split()]\nl,r=[],[]\nfor i in range(n):\n if x[i]<0 and i+1<n: l.append(abs(x[i]-min(x[i+1],0)))\n elif x[i]<0: l.append(-x[i])\n if x[i]>=0 and i>0: r.append(x[i]-max(0,x[i-1]))\n elif x[i]>=0: r.append(x[i])\n\nl=l[::-1]\nl=l[:k]\nr=r[:k]\nll=len(l)\nrr=len(r)\n\nans=sum(l)*2+sum(r)*2\nif ll==k: ans=min(ans,sum(l))\nif rr==k: ans=min(ans,sum(r))\nfor i in range(1,k):\n if rr>i and len(l[:-i])+i==k: ans=min(ans,(sum(r[:i])+sum(l[:-i])*2))\n if ll>i and len(r[:-i])+i==k: ans=min(ans,(sum(l[:i])+sum(r[:-i])*2))\n\nprint(ans)', 'n,k=map(int,input().split())\nx=[int(i) for i in input().split()]\nl,r=[],[]\nfor i in x:\n if i<0: l.append(-i)\n if i>=0: r.append(i)\nl.sort()\nr.sort()\nl=l[:k]\nr=r[:k]\nll=len(l)\nrr=len(r)\nlx,rx=[],[]\nfor i in range(ll):\n if i==0: lx.append(l[i])\n else: lx.append(l[i]-l[i-1])\nfor i in range(rr):\n if i==0: rx.append(r[i])\n else: rx.append(r[i]-r[i-1])\n\nans=sum(lx)*2+sum(rx)*2\nfor i in range(ll):\n if k-1==i: ans=min(ans,sum(lx))\n elif i+rr+1>=k: ans=min(ans,sum(lx[:i+1])*2+sum(rx[:k-i-1]))\n print(lx[:i+1],rx[:k-i-1])\n\nfor i in range(rr):\n if k-1==i: ans=min(ans,sum(rx))\n elif i+ll+1>=k: ans=min(ans,sum(rx[:i+1])*2+sum(lx[:k-i-1]))\n print(rx[:i+1],lx[:k-i-1])\nprint(ans)\n', 'n,k=map(int,input().split())\nx=[int(i) for i in input().split()]\nl,r=[],[]\nfor i in range(n):\n if x[i]<0 and i+1<n: l.append(abs(x[i]-min(x[i+1],0)))\n elif x[i]<0: l.append(-x[i])\n if x[i]>=0 and i>0: r.append(x[i]-max(0,x[i-1]))\n elif x[i]>=0: r.append(x[i])\n\nl=l[::-1]\nl=l[:k]\nr=r[:k]\n\nll=len(l)\nrr=len(r)\nlx=sum(l)\nrx=sum(r)\n\nif ll<k: lx=lx*2+sum(r[:(k-ll)])\nif rr<k: rx=rx*2+sum(l[:(k-rr)])\nans=min(lx,rx)\no=[ll,[0,k-ll][ll<k]]\np=[rr,[0,k-rr][rr<k]]\n\n\nfor i in range(1,k):\n if o[1]==0: lx*=2\n if p[1]==0: rx*=2\n if o[1]+1<=rr and o[0]>0:\n lx-=l[o[0]-1]*2\n lx+=r[o[1]]\n o[0]-=1\n o[1]+=1\n ans=min(ans,lx)\n if p[1]+1<=ll and p[0]>0:\n rx-=r[p[0]-1]*2\n rx+=l[p[1]]\n p[0]-=1\n p[1]+=1\n ans=min(ans,rx)\nprint(ans)\n'] | ['Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Accepted'] | ['s162847655', 's516950567', 's678684664', 's858884471', 's756566667'] | [14252.0, 14104.0, 14252.0, 145300.0, 14148.0] | [184.0, 391.0, 2104.0, 2104.0, 406.0] | [732, 879, 582, 708, 804] |
p03274 | u131638468 | 2,000 | 1,048,576 | There are N candles placed on a number line. The i-th candle from the left is placed on coordinate x_i. Here, x_1 < x_2 < ... < x_N holds. Initially, no candles are burning. Snuke decides to light K of the N candles. Now, he is at coordinate 0. He can move left and right along the line with speed 1. He can also light a candle when he is at the same position as the candle, in negligible time. Find the minimum time required to light K candles. | ["import numpy as np\nn,k,*x=map(int,open(0).read().split())\ninf=float('inf')\nk-=x.count(0)\nx=np.array(x)\npos=list(x[x>0])\nneg=list((x[x<0]*-1)[::-1])\nx=[]\nans=inf\nsum_p=pos[:min(len(pos),k)]\nsum_n=neg[:min(len(neg),k)]\npos.clear()\nneg.clear()\np_inf,n_inf=k-len(sum_p),k-len(sum_n)\nsum_p=sum_p+[inf for i in range(k-len(sum_p))]\nsum_n=sum_n+[inf for i in range(k-len(sum_n))]\nfor i in range(k):\n if k-1-i-n_inf < 0:\n continue\n ans=min(ans,sum_p[i]*2+sum_n[k-1-i-n_inf])\nfor i in range(k):\n if k-1-i-p_inf < 0:\n continue\n ans=min(ans,sum_n[i]*2+sum_p[k-1-i-p_inf])\nif k==0:\n ans=0\nprint(ans)", "n,k,*x=map(int,open(0).read().split())\nans=float('inf')\nif 0 in x:\n k-=1\n n-=1\n del x[x.index(0)]\n\nif k==0:\n print(0)\nelse:\n for i in range(n-k+1):\n ans=min(ans,abs(x[i])+abs(x[i]-x[i+k-1]))\n for i in range(k-1,n):\n ans=min(ans,abs(x[i])+abs(x[i]-x[i-(k-1)]))\n print(ans)"] | ['Wrong Answer', 'Accepted'] | ['s988149491', 's810728129'] | [37640.0, 20020.0] | [376.0, 98.0] | [598, 284] |
p03274 | u160244242 | 2,000 | 1,048,576 | There are N candles placed on a number line. The i-th candle from the left is placed on coordinate x_i. Here, x_1 < x_2 < ... < x_N holds. Initially, no candles are burning. Snuke decides to light K of the N candles. Now, he is at coordinate 0. He can move left and right along the line with speed 1. He can also light a candle when he is at the same position as the candle, in negligible time. Find the minimum time required to light K candles. | ['import numpy as np\n\nn, k = map(int, input().split())\nlst = list(map(int, input().split()))\n\narray = np.array(lst)\npo_array = array[array>=0]\nne_array = abs(array[array<0])\nne_array.sort()\n\nif len(po_array) >= len(ne_array):\n long_array = po_array\n short_array = ne_array\nelse:\n long_array = ne_array\n short_array = po_array\n\nif len(short_array) > k:\n min_len = k\nelse:\n min_len = len(short_array)\n \nif min_len == 0:\n print(long_array[k-1])\nelse:\n min_dist = 10**10\n for i in range(min_len):\n if i == k-1:\n dist = short_array[i]\n elif k-i-2 >= 0\n dist = short_array[i]*2 + long_array[k-i-2]\n if min_dist > dist:\n min_dist = dist\n if len(long_array) >= k:\n if min_dist > long_array[k-1]:\n min_dist = long_array[k-1]\n print(min_dist)', 'import numpy as np\n\nn, k = map(int, input().split())\nlst = list(map(int, input().split()))\n\narray = np.array(lst)\npo_array = array[array>=0]\nne_array = abs(array[array<0])\nne_array.sort()\n\nif len(po_array) >= len(ne_array):\n long_array = po_array\n short_array = ne_array\nelse:\n long_array = ne_array\n short_array = po_array\n\nif len(short_array) > k:\n min_len = k\nelse:\n min_len = len(short_array)\n \nif min_len == 0:\n print(long_array[k-1])\nelse:\n min_dist = 10**10\n for i in range(min_len):\n dist = 10**10\n if i == k-1:\n dist = short_array[i]\n elif k-i-1 <= len(long_array): \n dist = min(short_array[i]*2 + long_array[k-i-2], short_array[i] + long_array[k-i-2]*2)\n if min_dist > dist:\n min_dist = dist\n if len(long_array) >= k:\n if min_dist > long_array[k-1]:\n min_dist = long_array[k-1]\n print(min_dist)'] | ['Runtime Error', 'Accepted'] | ['s815151000', 's695173812'] | [3064.0, 23124.0] | [17.0, 393.0] | [842, 923] |
p03274 | u163320134 | 2,000 | 1,048,576 | There are N candles placed on a number line. The i-th candle from the left is placed on coordinate x_i. Here, x_1 < x_2 < ... < x_N holds. Initially, no candles are burning. Snuke decides to light K of the N candles. Now, he is at coordinate 0. He can move left and right along the line with speed 1. He can also light a candle when he is at the same position as the candle, in negligible time. Find the minimum time required to light K candles. | ['n,k=map(int,input().split())\narr=list(map(int,input().split()))\narr=sorted(arr)\nans=10**10\nfor i in range(n-k):\n if k==1:\n ans=min(ans,abs(arr[i]))\n else:\n if arr[i]*arr[i+k]>=0:\n ans=min(ans,min(abs(arr[i]),abs(arr[i+k])))\n else:\n ans=min(ans,min(2*abs(arr[i])+arr[i+k],abs(arr[i])+2*arr[i+k]))\nprint(ans)', 'n,k=map(int,input().split())\narr=list(map(int,input().split()))\narr=sorted(arr)\nans=10**10\nfor i in range(n-k+1):\n if k==1:\n ans=min(ans,abs(arr[i]))\n else:\n if arr[i]*arr[i+k-1]>=0:\n ans=min(ans,max(abs(arr[i]),abs(arr[i+k-1])))\n else:\n ans=min(ans,min(2*abs(arr[i])+arr[i+k-1],abs(arr[i])+2*arr[i+k-1]))\nprint(ans)'] | ['Wrong Answer', 'Accepted'] | ['s610529192', 's307902689'] | [14568.0, 14252.0] | [105.0, 103.0] | [327, 337] |
p03274 | u167681750 | 2,000 | 1,048,576 | There are N candles placed on a number line. The i-th candle from the left is placed on coordinate x_i. Here, x_1 < x_2 < ... < x_N holds. Initially, no candles are burning. Snuke decides to light K of the N candles. Now, he is at coordinate 0. He can move left and right along the line with speed 1. He can also light a candle when he is at the same position as the candle, in negligible time. Find the minimum time required to light K candles. | ['n, k = map(int, (input().split()))\n\nx = list(map(int, (input().split())))\nf = sorted([i if i >= 0 else -(i * 2) for i in x])\nb = sorted([-i if i < 0 else i * 2 for i in x ])\n\nmove = min(f[k - 1], b[k - 1])\n\na = [i for i in x if move >= abs(i)]\nprint(move + min(-a[0], a[-1]) if a[0] < 0 and 0 < a[-1] else move)', 'n, k = map(int, input().split())\nx = sorted([0] + list(map(int, input().split())))\n\nans = float("inf")\nfor i in range(n-k+1):\n ans = min(ans, min(abs(x[i]), abs(x[i+k])) + abs(x[i+k]-x[i]))\n\nprint(ans)'] | ['Wrong Answer', 'Accepted'] | ['s150220025', 's444859946'] | [15760.0, 14392.0] | [73.0, 90.0] | [312, 204] |
p03274 | u169138653 | 2,000 | 1,048,576 | There are N candles placed on a number line. The i-th candle from the left is placed on coordinate x_i. Here, x_1 < x_2 < ... < x_N holds. Initially, no candles are burning. Snuke decides to light K of the N candles. Now, he is at coordinate 0. He can move left and right along the line with speed 1. He can also light a candle when he is at the same position as the candle, in negligible time. Find the minimum time required to light K candles. | ['n,k=map(int,input().split())\nx=list(map(int,input().split()))\nlis=[]\nfor i in range(n-k+1):\n if x[i]<=0 and x[i+k-1]>=0:\n lis.append(min(x[i+k-1]-2*x[i],abs(x[i])-2*x[i+k-1]))\n elif x[i]>0 and x[i+k-1]<0:\n lis.append(min(x[i]-2*x[i+k-1],abs(x[i+k-1])-2*x[i]))\n else:\n lis.append(max(abs(x[i]),abs(x[i+k-1])))\nprint(min(lis))\n', 'n,k=map(int,input().split())\nx=list(map(int,input().split()))\nlis=[]\nfor i in range(n-k+1):\n if x[i]<=0 and x[i+k-1]>=0:\n lis.append(min(x[i+k-1]-2*x[i],abs(x[i])+2*x[i+k-1]))\n elif x[i]>0 and x[i+k-1]<0:\n lis.append(min(x[i]-2*x[i+k-1],abs(x[i+k-1])+2*x[i]))\n else:\n lis.append(max(abs(x[i]),abs(x[i+k-1])))\nprint(min(lis))\n'] | ['Wrong Answer', 'Accepted'] | ['s225584983', 's626419964'] | [14240.0, 14564.0] | [93.0, 96.0] | [337, 337] |
p03274 | u170183831 | 2,000 | 1,048,576 | There are N candles placed on a number line. The i-th candle from the left is placed on coordinate x_i. Here, x_1 < x_2 < ... < x_N holds. Initially, no candles are burning. Snuke decides to light K of the N candles. Now, he is at coordinate 0. He can move left and right along the line with speed 1. He can also light a candle when he is at the same position as the candle, in negligible time. Find the minimum time required to light K candles. | ['n, k = map(int, input().split())\nX = list(map(int, input().split()))\nl, r = -1, n\nwhile r - l > 1:\n p = (l + r) // 2\n if X[p] < 0:\n l = p\n else:\n r = p\n\nif l == -1:\n print(X[k - 1])\nelif r == n:\n print(abs(X[n - k + 1]))\nelse:\n best_score = 10 ** 9\n for i in range(max(l - k + 1, 0), n - k):\n print(i, i + k - 1, X[i], X[i + k - 1])\n score = 0\n if i > r:\n break\n if X[i + k] < 0:\n score = abs(X[i])\n elif X[i] > 0:\n score = X[i + k - 1]\n elif abs(X[i]) < abs(X[i + k - 1]):\n score = 2 * abs(X[i]) + X[i + k - 1]\n else:\n score = abs(X[i]) + 2 * X[i + k - 1]\n if score < best_score:\n best_score = score\n print(best_score)\n', 'n, k = map(int, input().split())\nX = list(map(int, input().split()))\nl, r = -1, n\nwhile r - l > 1:\n p = (l + r) // 2\n if X[p] < 0:\n l = p\n else:\n r = p\n\nif l == -1:\n print(X[k - 1])\nelif r == n:\n print(abs(X[n - k]))\nelif n == k:\n print(min(2 * abs(X[0]) + X[-1], abs(X[0]) + 2 * X[-1]))\nelse:\n best_score = 10 ** 9\n for i in range(max(l - k + 1, 0), n - k):\n score = 0\n if i > r:\n break\n if X[i + k] < 0:\n score = abs(X[i])\n elif X[i] > 0:\n score = X[i + k - 1]\n elif abs(X[i]) < abs(X[i + k - 1]):\n score = 2 * abs(X[i]) + X[i + k - 1]\n else:\n score = abs(X[i]) + 2 * X[i + k - 1]\n if score < best_score:\n best_score = score\n print(best_score)\n'] | ['Wrong Answer', 'Accepted'] | ['s543586372', 's371249215'] | [14228.0, 14696.0] | [202.0, 88.0] | [780, 802] |
p03274 | u175034939 | 2,000 | 1,048,576 | There are N candles placed on a number line. The i-th candle from the left is placed on coordinate x_i. Here, x_1 < x_2 < ... < x_N holds. Initially, no candles are burning. Snuke decides to light K of the N candles. Now, he is at coordinate 0. He can move left and right along the line with speed 1. He can also light a candle when he is at the same position as the candle, in negligible time. Find the minimum time required to light K candles. | ["n,k = map(int,input().split())\nx = list(map(int,input().split()))\n\nm = []\np = []\nfor i in range(n):\n if x[i] < 0:\n m.append(x[i])\n elif x[i] > 0:\n p.append(x[i])\n\nif m and p:\n if k-len(m) >= 0:\n s = 0\n else:\n s = abs(k-len(m))+1\n \n i = 0\n ans = float('inf')\n while s+i <= len(m) and z+s+i <= n:\n ans = min(ans, min(abs(x[s+i])*2 + abs(x[k-1+s+i]), abs(x[s+i]) + abs(x[k-1+s+i])*2))\n \n if s+i == len(m):\n ans = min(ans, x[k-1+s+i])\n if z+s+i == len(m)-1:\n ans = min(ans, abs(x[s+i]))\n i += 1\n \n print(ans)\nelif m:\n print(abs(x[-k]))\nelif p:\n print(x[k-1])\nelse:\n print(0)", "n,k = map(int,input().split())\nx = list(map(int,input().split()))\n\nm = []\np = []\nfor i in range(n):\n if x[i] < 0:\n m.append(x[i])\n elif x[i] > 0:\n p.append(x[i])\n\nif m and p:\n z = len(m)-1\n if k-len(m) >= 0:\n s = 0\n else:\n s = abs(k-len(m))+1\n \n i = 0\n ans = float('inf')\n while s+i <= len(m) and z+s+i <= n:\n ans = min(ans, min(abs(x[s+i])*2 + abs(x[k-1+s+i]), abs(x[s+i]) + abs(x[k-1+s+i])*2))\n \n if s+i == len(m):\n ans = min(ans, x[k-1+s+i])\n if z+s+i == len(m)-1:\n ans = min(ans, abs(x[s+i]))\n i += 1\n \n print(ans) \nelif m:\n print(abs(x[-k]))\nelif p:\n print(x[k-1])\nelse:\n print(0)", "n,k = map(int,input().split())\nx = list(map(int,input().split()))\n\nif len(x) == 1 and x[0] == 0:\n print(0)\n exit()\n\nm = []\np = []\nfor i in range(n):\n if x[i] < 0:\n m.append(x[i])\n elif x[i] > 0:\n p.append(x[i])\n\nans = float('inf')\nif len(m) >= k:\n ans = min(ans,abs(m[-k]))\n m = m[-k+1:]\nif len(p) >= k:\n ans = min(ans,p[k-1])\n p = p[:k-1]\n\nx = m+p\ni = 0\nfor i in range(len(x)-k+1):\n ans = min(ans, min(abs(x[i])*2+abs(x[i+k-1]), abs(x[i])+abs(x[i+k-1])*2))\n\nprint(ans)"] | ['Runtime Error', 'Runtime Error', 'Accepted'] | ['s106386451', 's139254460', 's459200837'] | [14240.0, 14252.0, 14252.0] | [71.0, 168.0, 122.0] | [694, 719, 510] |
p03274 | u175426149 | 2,000 | 1,048,576 | There are N candles placed on a number line. The i-th candle from the left is placed on coordinate x_i. Here, x_1 < x_2 < ... < x_N holds. Initially, no candles are burning. Snuke decides to light K of the N candles. Now, he is at coordinate 0. He can move left and right along the line with speed 1. He can also light a candle when he is at the same position as the candle, in negligible time. Find the minimum time required to light K candles. | ['# N, K = map(int, input().split())\n\n# X = list(map(int, input().split()))\n\nwith open("test.txt", \'r\') as f:\n N, K = map(int, f.readline().split())\n X = list(map(int, f.readline().split()))\n\ndef calc_time(x_max, x_min):\n if x_max * x_min >= 0:\n if abs(x_max) > abs(x_min):\n return x_max\n else:\n return abs(x_min)\n else:\n return x_max - x_min + min(abs(x_max), abs(x_min))\n\ndef calc_start_and_goal_position(index):\n if index - K >= 0:\n start_index = index - K\n else:\n start_index = 0\n \n if N > index + K + 1:\n goal_index = index + 1\n else:\n goal_index = N - K + 1\n \n return start_index, goal_index\n\nif __name__ == "__main__":\n index = -1\n for i, x in enumerate(X):\n if x >= 0:\n index = i \n break\n if index == -1:\n index = i\n start_index, goal_index = calc_start_and_goal_position(index)\n\n time_min = float(\'inf\')\n for i in range(start_index, goal_index):\n time = calc_time(X[i+K-1], X[i])\n if time < time_min:\n time_min = time\n print(time_min)', 'N, K = map(int, input().split())\n\nX = list(map(int, input().split()))\n\ndef calc_time(x_max, x_min):\n if x_max * x_min >= 0:\n if abs(x_max) > abs(x_min):\n return x_max\n else:\n return abs(x_min)\n else:\n return x_max - x_min + min(abs(x_max), abs(x_min))\n\ndef calc_start_and_goal_position(index):\n if index - K >= 0:\n start_index = index - K\n else:\n start_index = 0\n \n if N > index + K + 1:\n goal_index = index + 1\n else:\n goal_index = N - K + 1\n \n return start_index, goal_index\n\nif __name__ == "__main__":\n index = -1\n for i, x in enumerate(X):\n if x >= 0:\n index = i \n break\n if index == -1:\n index = i\n start_index, goal_index = calc_start_and_goal_position(index)\n\n time_min = float(\'inf\')\n for i in range(start_index, goal_index):\n time = calc_time(X[i+K-1], X[i])\n if time < time_min:\n time_min = time\n print(time_min)'] | ['Runtime Error', 'Accepted'] | ['s437293982', 's893054892'] | [3064.0, 14480.0] | [17.0, 83.0] | [1127, 1002] |
p03274 | u177040005 | 2,000 | 1,048,576 | There are N candles placed on a number line. The i-th candle from the left is placed on coordinate x_i. Here, x_1 < x_2 < ... < x_N holds. Initially, no candles are burning. Snuke decides to light K of the N candles. Now, he is at coordinate 0. He can move left and right along the line with speed 1. He can also light a candle when he is at the same position as the candle, in negligible time. Find the minimum time required to light K candles. | ['N,K = map(int,input().split())\nX = list(map(int,input().split()))\n\nfor i in range(N - K + 1):\n l = i\n r = i + K - 1\n\n Xl, Xr = X[l], X[r]\n if i == 0:\n ans = abs(Xl) + abs(Xr - Xl), abs(Xr) + abs(Xl - Xr)\n else:\n ans = min(abs(Xl) + abs(Xr - Xl), abs(Xr) + abs(Xl - Xr) , ans)\n\n\nprint(ans)\n', 'N,K = map(int,input().split())\nX = list(map(int,input().split()))\n\nfor i in range(N - K + 1):\n l = i\n r = i + K - 1\n\n Xl, Xr = X[l], X[r]\n if i == 0:\n ans = min(abs(Xl) + abs(Xr - Xl), abs(Xr) + abs(Xl - Xr))\n else:\n ans = min(abs(Xl) + abs(Xr - Xl), abs(Xr) + abs(Xl - Xr) , ans)\n\n\nprint(ans)\n'] | ['Runtime Error', 'Accepted'] | ['s504750564', 's947437335'] | [14384.0, 14252.0] | [42.0, 95.0] | [318, 323] |
p03274 | u189023301 | 2,000 | 1,048,576 | There are N candles placed on a number line. The i-th candle from the left is placed on coordinate x_i. Here, x_1 < x_2 < ... < x_N holds. Initially, no candles are burning. Snuke decides to light K of the N candles. Now, he is at coordinate 0. He can move left and right along the line with speed 1. He can also light a candle when he is at the same position as the candle, in negligible time. Find the minimum time required to light K candles. | ['n, m = map(int, input().split())\nlis = list(map(int, input().split()))\nsu = []\n\nfor i in range(n):\n su.append(lis[i] - lis[0])\n\nprint(su)\nres = 10**9\nfor i in range(n - m + 1):\n res = min(res, su[i + m - 1] - su[i] + min(abs(lis[i]), abs(lis[i + m - 1])))\nprint(res)\n', 'n, m = map(int, input().split())\nlis = list(map(int, input().split()))\n\nres = 10**9\nfor i in range(n - m + 1):\n res = min(res, lis[i + m - 1] - lis[i] + min(abs(lis[i]), abs(lis[i + m - 1])))\nprint(res)\n'] | ['Wrong Answer', 'Accepted'] | ['s946197330', 's886473389'] | [14636.0, 14252.0] | [114.0, 87.0] | [273, 206] |
p03274 | u192541825 | 2,000 | 1,048,576 | There are N candles placed on a number line. The i-th candle from the left is placed on coordinate x_i. Here, x_1 < x_2 < ... < x_N holds. Initially, no candles are burning. Snuke decides to light K of the N candles. Now, he is at coordinate 0. He can move left and right along the line with speed 1. He can also light a candle when he is at the same position as the candle, in negligible time. Find the minimum time required to light K candles. | ['n,k=map(int,input().split())\nlst1=input()\nlst2=lst1.split(" ")\nlst=[]\nfor i in lst2:\n lst.append(int(i))\n\nminr=[]\nminl=[]\n\nfor i in range(n-k+1):\n l=i\n r=i+k-1\n minr.sppend(abs(lst[r])+abs(lst[r]-lst[l]))\n minl.append(abs(lst[l])+abs(lst[r]-lst[l]))\n\nminr.sort()\nminl.sort()\n\nm=min(minr[0],minl[0])\nprint(m)', 'n,k=map(int,input().split())\nlst1=input()\nlst2=lst1.split(" ")\nlst=[]\nfor i in lst2:\n lst.append(int(i))\n\nminr=[]\nminl=[]\n\nfor i in range(n-k+1):\n l=i\n r=i+k-1\n minr.append(abs(lst[r])+abs(lst[r]-lst[l]))\n minl.append(abs(lst[l])+abs(lst[r]-lst[l]))\n\nminr.sort()\nminl.sort()\n\nm=min(minr[0],minl[0])\nprint(m)\n\n'] | ['Runtime Error', 'Accepted'] | ['s990945592', 's465796389'] | [15192.0, 19544.0] | [60.0, 114.0] | [322, 324] |
p03274 | u210827208 | 2,000 | 1,048,576 | There are N candles placed on a number line. The i-th candle from the left is placed on coordinate x_i. Here, x_1 < x_2 < ... < x_N holds. Initially, no candles are burning. Snuke decides to light K of the N candles. Now, he is at coordinate 0. He can move left and right along the line with speed 1. He can also light a candle when he is at the same position as the candle, in negligible time. Find the minimum time required to light K candles. | ['n,k=map(int,input().split())\n\nX=list(map(int,input().split()))\nV=[0]\nfor i in range(n-k):\n Y=X[i+k-1]-X[i] \n if X[i+k-1]<0:\n V.append(Y-X[i+k-1])\n elif X[i+k-1]>=0 and X[i]<0:\n V.append(Y+min(abs(X[i]),abs(X[i+k-1])))\n else:\n V.append(Y+X[i])\nprint(min(V))', 'n,k=map(int,input().split())\n\nX=list(map(int,input().split()))\nV=[]\nfor i in range(n-k+1):\n Y=X[i+k-1]-X[i] \n V.append(Y+min(abs(X[i]),abs(X[i+k-1])))\n\nprint(min(V))'] | ['Wrong Answer', 'Accepted'] | ['s711397627', 's203798566'] | [14532.0, 14384.0] | [100.0, 86.0] | [291, 173] |
p03274 | u219607170 | 2,000 | 1,048,576 | There are N candles placed on a number line. The i-th candle from the left is placed on coordinate x_i. Here, x_1 < x_2 < ... < x_N holds. Initially, no candles are burning. Snuke decides to light K of the N candles. Now, he is at coordinate 0. He can move left and right along the line with speed 1. He can also light a candle when he is at the same position as the candle, in negligible time. Find the minimum time required to light K candles. | ['N, K = map(int, input().split())\nX = list(map(int, input().split()))\nminval = 10000000000\nfor i in range(N-K+1):\n tmpval = abs(X[i]) + X[i+K-1] - X[i]\n if minval > tmpval:\n minval = tmpval\nX = reversed(X)\nfor i in range(N-K+1):\n tmpval = abs(X[i]) + X[i+K-1] - X[i]\n if minval > tmpval:\n minval = tmpval\nprint(minval)\n', 'N, K = map(int, input().split())\nX = list(map(int, input().split()))\nminval = 10000000000\nfor i in range(N-K+1):\n tmpval = abs(X[i]) + X[i+K-1] - X[i]\n if minval > tmpval:\n minval = tmpval\nX = -X[::-1]\nfor i in range(N-K+1):\n tmpval = abs(X[i]) + X[i+K-1] - X[i]\n if minval > tmpval:\n minval = tmpval\nprint(minval)', 'N, K = map(int, input().split())\nX = list(map(int, input().split()))\nminval = 10000000000\nfor i in range(N-K+1):\n tmpval = abs(X[i]) + X[i+K-1] - X[i]\n if minval > tmpval:\n minval = tmpval\nX = [-x for x in X[::-1]]\nfor i in range(N-K+1):\n tmpval = abs(X[i]) + X[i+K-1] - X[i]\n if minval > tmpval:\n minval = tmpval\nprint(minval)'] | ['Runtime Error', 'Runtime Error', 'Accepted'] | ['s284303255', 's484434778', 's994894954'] | [14224.0, 14568.0, 14224.0] | [66.0, 67.0, 94.0] | [344, 340, 353] |
p03274 | u221345507 | 2,000 | 1,048,576 | There are N candles placed on a number line. The i-th candle from the left is placed on coordinate x_i. Here, x_1 < x_2 < ... < x_N holds. Initially, no candles are burning. Snuke decides to light K of the N candles. Now, he is at coordinate 0. He can move left and right along the line with speed 1. He can also light a candle when he is at the same position as the candle, in negligible time. Find the minimum time required to light K candles. | ['import sys\nN,K=map(int,input().split())\na=list(map(int,input().split()))\n\nminus=[]\nfor i in range (N):\n if a[i]<0:\n minus.append(a[i])\nplus=a[len(minus):]\n\nif len(minus)==0:\n print(plus[K-1])\n sys.exit()\nif len(plus)==0:\n minus=minus[::-1]\n print(minus[K-1])\n sys.exit()\n\nif K==1:\n minus=minus[::-1]\n if len(plus)==0:\n plus.append(10**18)\n if len(minus)==0:\n minus.append(10**18)\n print(min(plus[0],abs(minus[0])))\n sys.exit()\n \ndata=[i * 2 for i in minus]+plus\ndata2=minus+[i * 2 for i in plus]\ndata_min=10**18\nfor i in range (N-K+1):\n if data_min >((abs(min(data[i],0)))+((abs(min(data[i+K-1],0))):\n data_min=((abs(min(data[i],0)))+((abs(min(data[i+K-1],0)))\nfor i in range (N-K+1):\n if data_min >((abs(min(data2[i],0)))+((abs(min(data2[i+K-1],0))):\n data_min=((abs(min(data2[i],0)))+((abs(min(data2[i+K-1],0)))\nprint(data_min)', 'import numpy as np\nN, K = map(int,input().split())\nx = list(map(int,input().split()))\n\nans = 10**9\nfor i in range (N-K+1):\n front = np.array(x[i])\n end = np.array(x[i+K-1])\n \n if np.sign(front)!= np.sign(end):\n ans_temp = min (abs(front)*2+abs(end),abs(front)+abs(end)*2)\n else:\n ans_temp = max(abs(front),abs(end))\n \n if ans_temp <= ans:\n ans = ans_temp\nprint(ans)'] | ['Runtime Error', 'Accepted'] | ['s946794644', 's053185502'] | [3064.0, 23088.0] | [18.0, 749.0] | [907, 409] |
p03274 | u223133214 | 2,000 | 1,048,576 | There are N candles placed on a number line. The i-th candle from the left is placed on coordinate x_i. Here, x_1 < x_2 < ... < x_N holds. Initially, no candles are burning. Snuke decides to light K of the N candles. Now, he is at coordinate 0. He can move left and right along the line with speed 1. He can also light a candle when he is at the same position as the candle, in negligible time. Find the minimum time required to light K candles. | ["N, K = map(int, input().split())\nX = list(map(int, input().split()))\n\nif N == 1:\n print(abs(X[0]))\n exit()\n\n\nflg = False\n\nfor x in X:\n if x < 0:\n flg = True\n\nif flg is False:\n print(X[K - 1])\n exit()\n\n\ndef sol(lft, rgt):\n print(X[lft], X[rgt])\n if X[lft] < 0 and X[rgt] < 0:\n return float('inf')\n elif X[lft] <= 0:\n return min(2 * abs(X[lft]) + X[rgt], abs(X[lft]) + 2 * X[rgt])\n else:\n return float('inf')\n\n\nlft, rgt = 0, 0\nans = float('inf')\nwhile True:\n\n if rgt == N - 1:\n break\n\n if rgt - lft + 1 < K:\n rgt += 1\n if rgt - lft + 1 == K:\n ans = min(ans, sol(lft, rgt))\n lft += 1\nprint(ans)\n", "N, K = map(int, input().split())\nX = list(map(int, input().split()))\n\nlft, rgt = 0, K - 1\nans = float('inf')\n\nwhile True:\n if rgt == N:\n break\n ans = min(ans, min(abs(X[lft]) + abs(X[lft] - X[rgt]),\n abs(X[rgt]) + abs(X[rgt] - X[lft])))\n lft += 1\n rgt += 1\nprint(ans)\n"] | ['Wrong Answer', 'Accepted'] | ['s783020119', 's160923144'] | [14480.0, 14224.0] | [207.0, 100.0] | [696, 309] |
p03274 | u225642513 | 2,000 | 1,048,576 | There are N candles placed on a number line. The i-th candle from the left is placed on coordinate x_i. Here, x_1 < x_2 < ... < x_N holds. Initially, no candles are burning. Snuke decides to light K of the N candles. Now, he is at coordinate 0. He can move left and right along the line with speed 1. He can also light a candle when he is at the same position as the candle, in negligible time. Find the minimum time required to light K candles. | ['INF = 10**9\n\nN, K = map(int, input().split())\nx_list = [int(i) for i in input().split()]\nfor i in range(N):\n if x_list[i] >= 0:\n T = i\n break\nelse:\n print(abs(x_list[-K])\n exit()\nmin_take_time = INF\nfor i in range(K+1):\n if T-K+i < 0 or T+i>N:\n continue\n if x_list[T-K+i] * x_list[T+i-1] <= 0:\n take_time = min(abs(x_list[T-K+i]), abs(x_list[T+i-1])) * 2 + max(abs(x_list[T-K+i]), abs(x_list[T+i-1]))\n else:\n take_time = max(abs(x_list[T-K+i]), abs(x_list[T+i-1]))\n min_take_time = min(min_take_time, take_time)\n\n\nprint(min_take_time)', 'INF = 10**9\n\nN, K = map(int, input().split())\nx_list = [int(i) for i in input().split()]\nfor i in range(N):\n if x_list[i] >= 0:\n T = i\n break\nelse:\n print(abs(x_list[-K]))\n exit()\nmin_take_time = INF\nfor i in range(K+1):\n if T-K+i < 0 or T+i>N:\n continue\n if x_list[T-K+i] * x_list[T+i-1] <= 0:\n take_time = min(abs(x_list[T-K+i]), abs(x_list[T+i-1])) * 2 + max(abs(x_list[T-K+i]), abs(x_list[T+i-1]))\n else:\n take_time = max(abs(x_list[T-K+i]), abs(x_list[T+i-1]))\n min_take_time = min(min_take_time, take_time)\n\n\nprint(min_take_time)'] | ['Runtime Error', 'Accepted'] | ['s492651828', 's845350736'] | [2940.0, 14664.0] | [17.0, 143.0] | [591, 592] |
p03274 | u226108478 | 2,000 | 1,048,576 | There are N candles placed on a number line. The i-th candle from the left is placed on coordinate x_i. Here, x_1 < x_2 < ... < x_N holds. Initially, no candles are burning. Snuke decides to light K of the N candles. Now, he is at coordinate 0. He can move left and right along the line with speed 1. He can also light a candle when he is at the same position as the candle, in negligible time. Find the minimum time required to light K candles. | ["# -*- coding: utf-8 -*-\n\n\ndef main():\n n, k = list(map(int, input().split()))\n x = list(map(int, input().split()))\n\n if x[0] < 0:\n diff = abs(x[0])\n\n for i in range(n):\n x[i] += diff\n\n print(min(x[k - 1]), x[-k])\n\n\nif __name__ == '__main__':\n main()\n", "# -*- coding: utf-8 -*-\n\n\ndef main():\n n, k = list(map(int, input().split()))\n x = list(map(int, input().split()))\n ans = float('inf')\n\n for i in range(n - k + 1):\n left = x[i]\n right = x[i + k - 1]\n abs_left = abs(left)\n abs_right = abs(right)\n\n if left * right >= 0:\n ans = min(ans, max(abs_left, abs_right))\n else:\n ans = min(ans, 2 * abs_left + abs_right, abs_left + 2 * abs_right)\n\n print(ans)\n\n\nif __name__ == '__main__':\n main()\n"] | ['Runtime Error', 'Accepted'] | ['s969038520', 's807998297'] | [14224.0, 14252.0] | [51.0, 73.0] | [290, 518] |
p03274 | u227020436 | 2,000 | 1,048,576 | There are N candles placed on a number line. The i-th candle from the left is placed on coordinate x_i. Here, x_1 < x_2 < ... < x_N holds. Initially, no candles are burning. Snuke decides to light K of the N candles. Now, he is at coordinate 0. He can move left and right along the line with speed 1. He can also light a candle when he is at the same position as the candle, in negligible time. Find the minimum time required to light K candles. | ['N, K = map(int, input().split())\nx = list(map(int, input().split()))\nassert len(x) == N\n\nm = min(x[i] - x[i-K+1] + min(abs(x[i], abs(x[i-K+1])) for i in range(K-1, N))\nprint(m)', 'N, K = map(int, input().split())\nx = list(map(int, input().split()))\nassert len(x) == N\n\nm = min(b - a + min(abs(a), abs(b)) for a, b in zip(x, x[K-1:]))\nprint(m)'] | ['Runtime Error', 'Accepted'] | ['s754833938', 's576345182'] | [2940.0, 15020.0] | [17.0, 60.0] | [178, 164] |
p03274 | u227082700 | 2,000 | 1,048,576 | There are N candles placed on a number line. The i-th candle from the left is placed on coordinate x_i. Here, x_1 < x_2 < ... < x_N holds. Initially, no candles are burning. Snuke decides to light K of the N candles. Now, he is at coordinate 0. He can move left and right along the line with speed 1. He can also light a candle when he is at the same position as the candle, in negligible time. Find the minimum time required to light K candles. | ['n,k=map(int,input().split())\nk-=1\nx=list(map(int,input().split()))\nprint(min(min(abs(x[i],x[i+k]))+abs(x[i]-x[i+k])for i in range(n-k)))', 'n,k=map(int,input().split())\nx=list(map(int,input().split()))\nprint(min(x[i]-x[i-k+1]+min(abs(x[i]),abs(x[i-k+1])) for i in range(k-1,n)))'] | ['Runtime Error', 'Accepted'] | ['s946248258', 's282487594'] | [14380.0, 14252.0] | [43.0, 75.0] | [136, 138] |
p03274 | u228223940 | 2,000 | 1,048,576 | There are N candles placed on a number line. The i-th candle from the left is placed on coordinate x_i. Here, x_1 < x_2 < ... < x_N holds. Initially, no candles are burning. Snuke decides to light K of the N candles. Now, he is at coordinate 0. He can move left and right along the line with speed 1. He can also light a candle when he is at the same position as the candle, in negligible time. Find the minimum time required to light K candles. | ['import bisect\n\nn,k= map(int,input().split())\nx = [int(i) for i in input().split()]\n\nidx = bisect.bisect_left(x,0)\n"""\nif x[idx] == 0:\n x.insert(idx,0)\n"""\n\nans = 10**100\n\nprint(x[idx])\n\nprint(ans)\nexit()\n\nfor i in range(k+1):\n #print(idx-i,idx+k-1-i)\n if i == 0 and idx+k-1 < n:\n ans = min(ans, x[idx+k-1])\n elif idx - i < 0 or idx+k-1-i >= n:\n continue\n else:\n ans = min(ans, - 2*x[idx-i] + x[idx+k-1-i])\n ans = min(ans, - x[idx-i] + 2*x[idx+k-1-i])\n\nprint(ans)', 'import bisect\n\nn,k= map(int,input().split())\nx = [int(i) for i in input().split()]\n\nidx = bisect.bisect_left(x,0)\n"""\nif x[idx] == 0:\n x.insert(idx,0)\n"""\n\nans = 10**100\n\nif x[idx] == 0 and idx - k + 1 >= 0:\n ans = min(ans,ans)\n\nprint(ans)\nexit()\n\nfor i in range(k+1):\n #print(idx-i,idx+k-1-i)\n if i == 0 and idx+k-1 < n:\n ans = min(ans, x[idx+k-1])\n elif idx - i < 0 or idx+k-1-i >= n:\n continue\n else:\n ans = min(ans, - 2*x[idx-i] + x[idx+k-1-i])\n ans = min(ans, - x[idx-i] + 2*x[idx+k-1-i])\n\nprint(ans)', 'import bisect\n\nn,k= map(int,input().split())\nx = [int(i) for i in input().split()]\n\nidx = bisect.bisect_left(x,0)\n"""\nif x[idx] == 0:\n x.insert(idx,0)\n"""\n\nans = 10**100\n\nif x[idx] == 0 and idx - k + 1 >= 0:\n ans = min(ans,-x[0])\n\nprint(ans)\nexit()\n\nfor i in range(k+1):\n #print(idx-i,idx+k-1-i)\n if i == 0 and idx+k-1 < n:\n ans = min(ans, x[idx+k-1])\n elif idx - i < 0 or idx+k-1-i >= n:\n continue\n else:\n ans = min(ans, - 2*x[idx-i] + x[idx+k-1-i])\n ans = min(ans, - x[idx-i] + 2*x[idx+k-1-i])\n\nprint(ans)', 'import bisect\n\nn,k= map(int,input().split())\nx = [int(i) for i in input().split()]\n\nidx = bisect.bisect_left(x,0)\n"""\nif x[idx] == 0:\n x.insert(idx,0)\n"""\n\nans = 10**100\n\nif x[idx] == 0:\n print(ans)\n\nprint(ans)\nexit()\n\nfor i in range(k+1):\n #print(idx-i,idx+k-1-i)\n if i == 0 and idx+k-1 < n:\n ans = min(ans, x[idx+k-1])\n elif idx - i < 0 or idx+k-1-i >= n:\n continue\n else:\n ans = min(ans, - 2*x[idx-i] + x[idx+k-1-i])\n ans = min(ans, - x[idx-i] + 2*x[idx+k-1-i])\n\nprint(ans)', 'import bisect\n\nn,k= map(int,input().split())\nx = [int(i) for i in input().split()]\n\nidx = bisect.bisect_left(x,0)\n"""\nif x[idx] == 0:\n x.insert(idx,0)\n"""\n\nans = 10**100\n\nif x[idx] == 0 and idx - k + 1 >= 0:\n print(ans)\n\nprint(ans)\nexit()\n\nfor i in range(k+1):\n #print(idx-i,idx+k-1-i)\n if i == 0 and idx+k-1 < n:\n ans = min(ans, x[idx+k-1])\n elif idx - i < 0 or idx+k-1-i >= n:\n continue\n else:\n ans = min(ans, - 2*x[idx-i] + x[idx+k-1-i])\n ans = min(ans, - x[idx-i] + 2*x[idx+k-1-i])\n\nprint(ans)', 'import bisect\n\nn,k= map(int,input().split())\nx = [int(i) for i in input().split()]\n\nidx = bisect.bisect_left(x,0)\n"""\nif x[idx] == 0:\n x.insert(idx,0)\n"""\n\nans = 10**100\n\nif x[idx] == 0 and idx - k + 1 >= 0:\n ans = min(ans,-x[idx-k+1])\n\nprint(ans)\nexit()\n\nfor i in range(k+1):\n #print(idx-i,idx+k-1-i)\n if i == 0 and idx+k-1 < n:\n ans = min(ans, x[idx+k-1])\n elif idx - i < 0 or idx+k-1-i >= n:\n continue\n else:\n ans = min(ans, - 2*x[idx-i] + x[idx+k-1-i])\n ans = min(ans, - x[idx-i] + 2*x[idx+k-1-i])\n\nprint(ans)', 'import bisect\n\nn,k= map(int,input().split())\nx = [int(i) for i in input().split()]\n\nidx = bisect.bisect_left(x,0)\n"""\nif x[idx] == 0:\n x.insert(idx,0)\n"""\nans = 10**100\n\n\nfor i in range(k+1):\n #print(idx-i,idx+k-1-i)\n if i == 0 and idx+k-1 < n:\n ans = min(ans, x[idx+k-1])\n elif idx - i < 0 or idx+k-1-i >= n:\n continue\n else:\n ans = min(ans, - 2*x[idx-i] + x[idx+k-1-i])\n ans = min(ans, - x[idx-i] + 2*x[idx+k-1-i])\n\nif idx == n:\n ans = -x[-k]\n\nprint(ans)'] | ['Runtime Error', 'Runtime Error', 'Runtime Error', 'Runtime Error', 'Runtime Error', 'Runtime Error', 'Accepted'] | ['s111704207', 's218647099', 's532468726', 's722839661', 's756330534', 's759999186', 's420872575'] | [14564.0, 14660.0, 14548.0, 14660.0, 14548.0, 14564.0, 14548.0] | [47.0, 49.0, 47.0, 47.0, 48.0, 49.0, 124.0] | [505, 551, 553, 522, 543, 559, 502] |
p03274 | u231095456 | 2,000 | 1,048,576 | There are N candles placed on a number line. The i-th candle from the left is placed on coordinate x_i. Here, x_1 < x_2 < ... < x_N holds. Initially, no candles are burning. Snuke decides to light K of the N candles. Now, he is at coordinate 0. He can move left and right along the line with speed 1. He can also light a candle when he is at the same position as the candle, in negligible time. Find the minimum time required to light K candles. | ['N, K = map(int,input().split())\nx = list(map(int,input().split()))\nleft = []\nright = []\nfor a in x:\n if a < 0:\n left = [-a]+left\n elif a == 0:\n K -= 1\n else:\n right.append(a)\nans = float("inf") if K > 0 else 0\nif K == 0:\n print(0)\n exit(0)\nif right == []:\n ans = left[K-1]\nelif left == []:\n ans = right[K-1]\nelse:\n for l in range(min(len(left)+1, K+1)):\n r = K-l\n if l == 0 and len(right) >= r:\n print(right, r)\n ans = min(ans, right[r-1])\n elif l == K and len(left) >= l:\n ans = min(ans, left[l-1])\n elif len(left) >= l and len(right) >= r:\n ans = min(ans, 2*left[l-1]+right[r-1])\n ans = min(ans, left[l-1]+2*right[r-1])\nprint(ans)', 'N, K = map(int,input().split())\nx = list(map(int,input().split()))\nans = float("inf")\nfor i in range(N-K+1):\n ans = min(ans, abs(x[i])+abs(x[i]-x[i+K-1]))\n ans = min(ans, abs(x[i+K-1])+abs(x[i]-x[i+K-1]))\nprint(ans)'] | ['Wrong Answer', 'Accepted'] | ['s545698015', 's552086300'] | [20076.0, 20072.0] | [2206.0, 103.0] | [760, 221] |
p03274 | u250583425 | 2,000 | 1,048,576 | There are N candles placed on a number line. The i-th candle from the left is placed on coordinate x_i. Here, x_1 < x_2 < ... < x_N holds. Initially, no candles are burning. Snuke decides to light K of the N candles. Now, he is at coordinate 0. He can move left and right along the line with speed 1. He can also light a candle when he is at the same position as the candle, in negligible time. Find the minimum time required to light K candles. | ["import sys\ndef input(): return sys.stdin.readline().rstrip()\n\ndef solve(l, m):\n print(l, m)\n if l < m:\n return l * 2 + m\n else:\n return l + m * 2\n\ndef main():\n N, K = map(int, input().split())\n x = tuple(map(int, input().split()))\n right_x = [i for i in x if i >= 0][:K]\n left_x = [-i for i in x if i < 0][-K:]\n\n left_len = len(left_x)\n right_len = len(right_x)\n if right_len < K:\n right_x += [10 ** 8 + 1] * (K - right_len)\n if left_len < K:\n left_x = [10 ** 8 + 1] * (K - left_len) + left_x\n\n right_x = [0] + right_x\n left_x += [0]\n\n ans = 10 ** 9\n for i in range(K + 1):\n tmp_ans = solve(left_x[i], right_x[i])\n if tmp_ans < ans:\n ans = tmp_ans\n print(ans)\n\nif __name__ == '__main__':\n main()\n", "import sys\ndef input(): return sys.stdin.readline().rstrip()\n\ndef solve(l, r):\n lv = abs(l)\n rv = abs(r)\n if (l < 0) ^ (r < 0):\n return lv + rv + min(lv, rv)\n else:\n return max(lv, rv)\n\ndef main():\n N, K = map(int, input().split())\n x = tuple(map(int, input().split()))\n\n ans = 10 ** 9\n for i in range(N - K + 1):\n tmp_ans = solve(x[i], x[i + K - 1])\n if tmp_ans < ans:\n ans = tmp_ans\n\n print(ans)\n\nif __name__ == '__main__':\n main()\n"] | ['Wrong Answer', 'Accepted'] | ['s939728094', 's220425643'] | [15024.0, 15028.0] | [188.0, 69.0] | [800, 503] |
p03274 | u255280439 | 2,000 | 1,048,576 | There are N candles placed on a number line. The i-th candle from the left is placed on coordinate x_i. Here, x_1 < x_2 < ... < x_N holds. Initially, no candles are burning. Snuke decides to light K of the N candles. Now, he is at coordinate 0. He can move left and right along the line with speed 1. He can also light a candle when he is at the same position as the candle, in negligible time. Find the minimum time required to light K candles. | ["import sys\nimport math\nimport collections\nimport itertools\nimport array\nimport inspect\n\n\nsys.setrecursionlimit(1000000)\n\n\n# Debug output\ndef chkprint(*args):\n names = {\n id(v): k\n for k, v in inspect.currentframe().f_back.f_locals.items()\n }\n print(', '.join(\n names.get(id(arg), '???') + ' = ' + repr(arg) for arg in args))\n\n\n# Binary converter\ndef to_bin(x):\n return bin(x)[2:]\n\n\ndef li_input():\n return [int(_) for _ in sys.stdin.readline().split()]\n\n\ndef gcd(n, m):\n if n % m == 0:\n return m\n else:\n return gcd(m, n % m)\n\n\ndef gcd_list(L):\n v = L[0]\n\n for i in range(1, len(L)):\n v = gcd(v, L[i])\n\n return v\n\n\ndef lcm(n, m):\n return (n * m) // gcd(n, m)\n\n\ndef lcm_list(L):\n v = L[0]\n\n for i in range(1, len(L)):\n v = lcm(v, L[i])\n\n return v\n\n\n# Width First Search (+ Distance)\ndef wfs_d(D, N, K):\n \n\n dfk = [-1] * (N + 1)\n dfk[K] = 0\n\n cps = [(K, 0)]\n r = [False] * (N + 1)\n r[K] = True\n while len(cps) != 0:\n n_cps = []\n for cp, cd in cps:\n for i, dfcp in enumerate(D[cp]):\n if dfcp != -1 and not r[i]:\n dfk[i] = cd + dfcp\n n_cps.append((i, cd + dfcp))\n r[i] = True\n\n cps = n_cps[:]\n\n return dfk\n\n\n# Depth First Search (+Distance)\ndef dfs_d(v, pre, dist):\n \n\n global D\n global D_dfs_d\n\n D_dfs_d[v] = dist\n\n for next_v, d in D[v]:\n if next_v != pre:\n dfs_d(next_v, v, dist + d)\n\n return\n\n\ndef sigma(N):\n ans = 0\n for i in range(1, N + 1):\n ans += i\n return ans\n\n\ndef comb(n, r):\n if n - r < r: r = n - r\n if r == 0: return 1\n if r == 1: return n\n\n numerator = [n - r + k + 1 for k in range(r)]\n denominator = [k + 1 for k in range(r)]\n\n for p in range(2, r + 1):\n pivot = denominator[p - 1]\n if pivot > 1:\n offset = (n - r) % p\n for k in range(p - 1, r, p):\n numerator[k - offset] /= pivot\n denominator[k] /= pivot\n\n result = 1\n for k in range(r):\n if numerator[k] > 1:\n result *= int(numerator[k])\n\n return result\n\ndef bisearch(L, target):\n low = 0\n high = len(L) - 1\n \n while low <= high:\n mid = (low + high) // 2\n guess = L[mid]\n if guess == target:\n return True\n elif guess < target:\n low = mid + 1\n elif guess > target:\n high = mid - 1\n if guess != target:\n return False\n\n# --------------------------------------------\n\ndp = None\n\n\ndef main():\n N, K = li_input()\n A = li_input()\n D = []\n\n for i in range(N - K + 1):\n l,r = A[i],A[i+K-1]\n D.append(min(abs(l) + abs(r - l), abs(r), abs(l - r)))\n\n print(min(D))\n\n\nmain()\n", "import sys\nimport math\nimport collections\nimport itertools\nimport array\nimport inspect\n\n\nsys.setrecursionlimit(1000000)\n\n\n# Debug output\ndef chkprint(*args):\n names = {\n id(v): k\n for k, v in inspect.currentframe().f_back.f_locals.items()\n }\n print(', '.join(\n names.get(id(arg), '???') + ' = ' + repr(arg) for arg in args))\n\n\n# Binary converter\ndef to_bin(x):\n return bin(x)[2:]\n\n\ndef li_input():\n return [int(_) for _ in sys.stdin.readline().split()]\n\n\ndef gcd(n, m):\n if n % m == 0:\n return m\n else:\n return gcd(m, n % m)\n\n\ndef gcd_list(L):\n v = L[0]\n\n for i in range(1, len(L)):\n v = gcd(v, L[i])\n\n return v\n\n\ndef lcm(n, m):\n return (n * m) // gcd(n, m)\n\n\ndef lcm_list(L):\n v = L[0]\n\n for i in range(1, len(L)):\n v = lcm(v, L[i])\n\n return v\n\n\n# Width First Search (+ Distance)\ndef wfs_d(D, N, K):\n \n\n dfk = [-1] * (N + 1)\n dfk[K] = 0\n\n cps = [(K, 0)]\n r = [False] * (N + 1)\n r[K] = True\n while len(cps) != 0:\n n_cps = []\n for cp, cd in cps:\n for i, dfcp in enumerate(D[cp]):\n if dfcp != -1 and not r[i]:\n dfk[i] = cd + dfcp\n n_cps.append((i, cd + dfcp))\n r[i] = True\n\n cps = n_cps[:]\n\n return dfk\n\n\n# Depth First Search (+Distance)\ndef dfs_d(v, pre, dist):\n \n\n global D\n global D_dfs_d\n\n D_dfs_d[v] = dist\n\n for next_v, d in D[v]:\n if next_v != pre:\n dfs_d(next_v, v, dist + d)\n\n return\n\n\ndef sigma(N):\n ans = 0\n for i in range(1, N + 1):\n ans += i\n return ans\n\n\ndef comb(n, r):\n if n - r < r: r = n - r\n if r == 0: return 1\n if r == 1: return n\n\n numerator = [n - r + k + 1 for k in range(r)]\n denominator = [k + 1 for k in range(r)]\n\n for p in range(2, r + 1):\n pivot = denominator[p - 1]\n if pivot > 1:\n offset = (n - r) % p\n for k in range(p - 1, r, p):\n numerator[k - offset] /= pivot\n denominator[k] /= pivot\n\n result = 1\n for k in range(r):\n if numerator[k] > 1:\n result *= int(numerator[k])\n\n return result\n\ndef bisearch(L, target):\n low = 0\n high = len(L) - 1\n \n while low <= high:\n mid = (low + high) // 2\n guess = L[mid]\n if guess == target:\n return True\n elif guess < target:\n low = mid + 1\n elif guess > target:\n high = mid - 1\n if guess != target:\n return False\n\n# --------------------------------------------\n\ndp = None\n\n\ndef main():\n N, K = li_input()\n A = li_input()\n D = []\n\n for i in range(N - K + 1):\n l,r = A[i],A[i+K-1]\n D.append(min(abs(l) + abs(r - l), abs(r), abs(r - l)))\n\n print(min(D))\n\n\nmain()\n", "import sys\nimport math\nimport collections\nimport itertools\nimport array\nimport inspect\n\n\nsys.setrecursionlimit(1000000)\n\n\n# Debug output\ndef chkprint(*args):\n names = {\n id(v): k\n for k, v in inspect.currentframe().f_back.f_locals.items()\n }\n print(', '.join(\n names.get(id(arg), '???') + ' = ' + repr(arg) for arg in args))\n\n\n# Binary converter\ndef to_bin(x):\n return bin(x)[2:]\n\n\ndef li_input():\n return [int(_) for _ in sys.stdin.readline().split()]\n\n\ndef gcd(n, m):\n if n % m == 0:\n return m\n else:\n return gcd(m, n % m)\n\n\ndef gcd_list(L):\n v = L[0]\n\n for i in range(1, len(L)):\n v = gcd(v, L[i])\n\n return v\n\n\ndef lcm(n, m):\n return (n * m) // gcd(n, m)\n\n\ndef lcm_list(L):\n v = L[0]\n\n for i in range(1, len(L)):\n v = lcm(v, L[i])\n\n return v\n\n\n# Width First Search (+ Distance)\ndef wfs_d(D, N, K):\n \n\n dfk = [-1] * (N + 1)\n dfk[K] = 0\n\n cps = [(K, 0)]\n r = [False] * (N + 1)\n r[K] = True\n while len(cps) != 0:\n n_cps = []\n for cp, cd in cps:\n for i, dfcp in enumerate(D[cp]):\n if dfcp != -1 and not r[i]:\n dfk[i] = cd + dfcp\n n_cps.append((i, cd + dfcp))\n r[i] = True\n\n cps = n_cps[:]\n\n return dfk\n\n\n# Depth First Search (+Distance)\ndef dfs_d(v, pre, dist):\n \n\n global D\n global D_dfs_d\n\n D_dfs_d[v] = dist\n\n for next_v, d in D[v]:\n if next_v != pre:\n dfs_d(next_v, v, dist + d)\n\n return\n\n\ndef sigma(N):\n ans = 0\n for i in range(1, N + 1):\n ans += i\n return ans\n\n\ndef comb(n, r):\n if n - r < r: r = n - r\n if r == 0: return 1\n if r == 1: return n\n\n numerator = [n - r + k + 1 for k in range(r)]\n denominator = [k + 1 for k in range(r)]\n\n for p in range(2, r + 1):\n pivot = denominator[p - 1]\n if pivot > 1:\n offset = (n - r) % p\n for k in range(p - 1, r, p):\n numerator[k - offset] /= pivot\n denominator[k] /= pivot\n\n result = 1\n for k in range(r):\n if numerator[k] > 1:\n result *= int(numerator[k])\n\n return result\n\ndef bisearch(L, target):\n low = 0\n high = len(L) - 1\n \n while low <= high:\n mid = (low + high) // 2\n guess = L[mid]\n if guess == target:\n return True\n elif guess < target:\n low = mid + 1\n elif guess > target:\n high = mid - 1\n if guess != target:\n return False\n\n# --------------------------------------------\n\ndp = None\n\n\ndef main():\n N, K = li_input()\n A = li_input()\n D = []\n\n for i in range(N - K + 1):\n l,r = A[i],A[i+K-1]\n D.append(min(abs(l) + abs(r - l), abs(r) + abs(r - l)))\n\n print(min(D))\n\n\nmain()\n"] | ['Wrong Answer', 'Wrong Answer', 'Accepted'] | ['s528062341', 's982774909', 's755481738'] | [16612.0, 16532.0, 15844.0] | [104.0, 94.0, 97.0] | [3194, 3194, 3195] |
p03274 | u259861571 | 2,000 | 1,048,576 | There are N candles placed on a number line. The i-th candle from the left is placed on coordinate x_i. Here, x_1 < x_2 < ... < x_N holds. Initially, no candles are burning. Snuke decides to light K of the N candles. Now, he is at coordinate 0. He can move left and right along the line with speed 1. He can also light a candle when he is at the same position as the candle, in negligible time. Find the minimum time required to light K candles. | ['N, K = map(int, input().split())\nx = list(map(int, input().split()))\n\ncost = float("inf")\n\nfor l in range(N-K+1):\n r = l+K-1\n from_left = abs(x[l]+abs(x[r]-x[l]))\n from_right = abs(x[r]+abs(x[l]-x[r]))\n cost = min(cost, from_left, from_right)\nprint(cost)\n\n', 'N, K = map(int, input().split())\nx = list(map(int, input().split()))\n\nans = float("inf")\n\nfor i in range(N-K+1):\n lef = x[i]\n rig = x[i+K-1]\n ans = min(ans, abs(lef)+abs(rig-lef), abs(rig)+abs(rig-lef))\nprint(ans)\n'] | ['Wrong Answer', 'Accepted'] | ['s192378423', 's938711551'] | [14384.0, 15020.0] | [91.0, 86.0] | [268, 223] |
p03274 | u263654061 | 2,000 | 1,048,576 | There are N candles placed on a number line. The i-th candle from the left is placed on coordinate x_i. Here, x_1 < x_2 < ... < x_N holds. Initially, no candles are burning. Snuke decides to light K of the N candles. Now, he is at coordinate 0. He can move left and right along the line with speed 1. He can also light a candle when he is at the same position as the candle, in negligible time. Find the minimum time required to light K candles. | ['for i in range(n-k+1):\n xtmp = x[i:i+k]\n# print(i, xtmp)\n\n if i==0:\n MIN = abs(xtmp[0])+2*abs(xtmp[-1])\n\n MIN = min(MIN, abs(xtmp[0]-xtmp[-1]) + abs(xtmp[0]))\n MIN = min(MIN, abs(xtmp[0]-xtmp[-1]) + abs(xtmp[-1]))\n\nprint(MIN)', 'n, k = map(int, input().split())\nx = list(map(int, input().split()))\n\nfor i in range(n-k+1):\n xtmp = x[i:i+k]\n print(i, xtmp)\n\n if i==0:\n MIN = abs(xtmp[0])+2*abs(xtmp[-1])\n\n MIN = min(MIN, abs(xtmp[0]-xtmp[-1]) + abs(xtmp[0]))\n MIN = min(MIN, abs(xtmp[0]-xtmp[-1]) + abs(xtmp[-1]))\n\n i+=1\n\nprint(MIN)', 'n, k = map(int, input().split())\nx = list(map(int, input().split()))\n\nfor i in range(n-k+1):\n xl = x[i]\n xr = x[i+k-1]\n if i==0:\n MIN = abs(xl-xr) + abs(xl)\n\n MIN = min(MIN, abs(xl-xr) + abs(xl))\n MIN = min(MIN, abs(xl-xr) + abs(xr))\n\nprint(MIN)'] | ['Runtime Error', 'Runtime Error', 'Accepted'] | ['s413096513', 's470412287', 's755368614'] | [3060.0, 141212.0, 14224.0] | [17.0, 1355.0, 98.0] | [248, 326, 267] |
p03274 | u282228874 | 2,000 | 1,048,576 | There are N candles placed on a number line. The i-th candle from the left is placed on coordinate x_i. Here, x_1 < x_2 < ... < x_N holds. Initially, no candles are burning. Snuke decides to light K of the N candles. Now, he is at coordinate 0. He can move left and right along the line with speed 1. He can also light a candle when he is at the same position as the candle, in negligible time. Find the minimum time required to light K candles. | ['N,K = map(int,input().split())\nX = list(map(int,input().split()))\nres = 10**10\nfor i in range(N-K+1):\n if X[i]*X[i+K-1] >= 0:\n res = min(res,max(abs(X[i+K-1],X[i])))\n else:\n res = min(res,abs(X[i])*2+X[i+K-1],X[i+K-1]*2+abs(X[i]))\nprint(res)', 'N,K = map(int,input().split())\nX = list(map(int,input().split()))\nres = 10**10\nfor i in range(N-K+1):\n if X[i]*X[i+K-1] >= 0:\n res = min(res,max(abs(X[i+K-1]),abs(X[i])))\n else:\n res = min(res,abs(X[i])*2+X[i+K-1],X[i+K-1]*2+abs(X[i]))\nprint(res)'] | ['Runtime Error', 'Accepted'] | ['s757382337', 's977421647'] | [14252.0, 14568.0] | [92.0, 91.0] | [261, 266] |
p03274 | u288087195 | 2,000 | 1,048,576 | There are N candles placed on a number line. The i-th candle from the left is placed on coordinate x_i. Here, x_1 < x_2 < ... < x_N holds. Initially, no candles are burning. Snuke decides to light K of the N candles. Now, he is at coordinate 0. He can move left and right along the line with speed 1. He can also light a candle when he is at the same position as the candle, in negligible time. Find the minimum time required to light K candles. | ['import numpy as np\n\nN, K = list(map(int, input().split()))\n\nx = list(map(int, input().split()))\n\n\ndef my_index(l, i, default=False):\n if i in l:\n return True\n else:\n return default\n\n\ndef main():\n global x, K\n if 0 in x:\n K -= 1\n if K == 0:\n return 0\n\n x = np.array(x)\n positives = x[np.where(x > 0)]\n negatives = x[np.where(x < 0)]\n\n nega_size = np.size(negatives)\n posi_size = np.size(positives)\n if nega_size == 0:\n return positives[K-1]\n\n if posi_size == 0:\n return abs(negatives[-K])\n\n if K <= nega_size and K <= posi_size:\n min = positives[K-1]\n for i in range(K+1):\n if i == 0:\n continue\n elif i == K:\n tmp = abs(negatives[nega_size-K])\n min = tmp if min > tmp else min\n elif i > 0 and i < K+1:\n new_posi = positives[:K-i]\n new_nega = negatives[nega_size-i:]\n tmp = 2 * new_posi[-1] + abs(new_nega[0])\n if tmp > new_posi[-1] + 2 * abs(new_nega[0]):\n tmp = new_posi[-1] + 2 * abs(new_nega[0])\n min = tmp if min > tmp else min\n\n return min\n\n if K > nega_size and K > posi_size:\n min = 1e9\n for i in range(N-K+1):\n ne = abs(x[i])\n po = x[N + i - K+1]\n tmp = ne + 2 * po\n if tmp > 2 * ne + po:\n tmp = 2 * ne + po\n\n min = tmp if min > tmp else min\n\n return min\n\n if nega_size < K and K <= posi_size:\n min = positives[K-1]\n for i in range(1, nega_size):\n tmp = abs(negatives[-i]) + 2 * positives[K-i] if abs(negatives[-i]\n ) > positives[K-i] else 2 * abs(negatives[-i]) + positives[K-i]\n min = tmp if min > tmp else min\n\n return min\n\n if posi_size < K and K <= nega_size:\n min = negatives[-1]\n for i in range(1, posi_size):\n tmp = positives[-i-1] + 2 * abs(negatives[-i]) if abs(\n negatives[-i]) < positives[-i-1] else 2 * positives[-i-1] + abs(negatives[-i])\n min = tmp if min > tmp else min\n\n return min\n\n\nprint(main())\n', 'import numpy as np\n\nN, K = list(map(int, input().split()))\n\nx = list(map(int, input().split()))\n\n\ndef calc(m, n, default=100000000):\n tmp = 0\n if m > n:\n tmp = m + 2*n\n else:\n tmp = 2*m + n\n\n min = tmp if default > tmp else default\n\n return min\n\n\ndef my_index(l, i, default=False):\n if i in l:\n return True\n else:\n return default\n\n\ndef main():\n global x, K\n if 0 in x:\n K -= 1\n if K == 0:\n return 0\n\n x = np.array(x)\n positives = x[np.where(x > 0)]\n negatives = x[np.where(x < 0)]\n\n nega_size = np.size(negatives)\n posi_size = np.size(positives)\n if nega_size == 0:\n return positives[K-1]\n\n if posi_size == 0:\n return abs(negatives[-K])\n\n if K <= nega_size and K <= posi_size:\n min = 1e9\n for i in range(K+1):\n if i == 0:\n min = abs(negatives[-K])\n elif i > 0 and i < K:\n ne = abs(negatives[-K+i])\n po = positives[i-1]\n min = calc(ne, po, min)\n elif i == K:\n tmp = positives[K-1]\n min = tmp if min > tmp else min\n\n return min\n\n if K > nega_size and K > posi_size:\n min = 1e9\n for i in range(N-K+1):\n ne = abs(x[i])\n po = x[K+i-1]\n min = calc(ne, po, min)\n\n return min\n\n if nega_size < K and K <= posi_size:\n min = 1e9\n for i in range(nega_size):\n po = x[K+i-1]\n ne = abs(x[i])\n min = calc(ne, po, min)\n\n min = abs(positives[K-1]) if abs(positives[K-1]) < min else min\n return min\n\n if posi_size < K and K <= nega_size:\n min = 1e9\n for i in range(posi_size):\n po = x[-i-1]\n ne = abs(x[-K-i])\n min = calc(po, ne, min)\n\n min = abs(negatives[-K]) if abs(negatives[-K]) < min else min\n return min\n\n\nprint(main())\n'] | ['Wrong Answer', 'Accepted'] | ['s211677721', 's118262619'] | [23088.0, 23140.0] | [290.0, 287.0] | [2269, 1955] |
p03274 | u300968187 | 2,000 | 1,048,576 | There are N candles placed on a number line. The i-th candle from the left is placed on coordinate x_i. Here, x_1 < x_2 < ... < x_N holds. Initially, no candles are burning. Snuke decides to light K of the N candles. Now, he is at coordinate 0. He can move left and right along the line with speed 1. He can also light a candle when he is at the same position as the candle, in negligible time. Find the minimum time required to light K candles. | ['n, k = map(int, input().split())\nx = list(map(int, input().split()))\nfirst = True\nfor l, r in zip(range(0, n - k + 1), range(k - 1, n)):\n if 0 >= x[r]:\n if first:\n min_time = -x[l]\n else:\n time =-x[l]\n if time < min_time:\n min_time = time\n elif 0 <= x[l]:\n if first:\n min_time = x[r]\n else:\n time = x[r]\n if time < min_time:\n min_time = time\n else:\n if first:\n min_time = 2 * (x[r] - x[l]) - max(-x[l], x[r])\n brk = True\n else:\n time = 2 * (x[r] - x[l]) - max(-x[l], x[r])\n if time < min_time:\n min_time = time\nprint(min_time)', 'n, k = map(int, input().split())\nx = list(map(int, input().split()))\nfirst = True\nfor l, r in zip(range(0, n - k + 1), range(k - 1, n)):\n if 0 >= x[r]:\n if first:\n min_time = -x[l]\n else:\n time =-x[l]\n if time < min_time:\n min_time = time\n elif 0 <= x[l]:\n if first:\n min_time = x[r]\n break\n else:\n if first:\n min_time = 2 * (x[r] - x[l]) - max(-x[l], x[r])\n brk = True\n else:\n time = 2 * (x[r] - x[l]) - max(-x[l], x[r])\n if time < min_time:\n min_time = time\nprint(min_time)', 'n, k = map(int, input().split())\nx = list(map(int, input().split()))\nmin_time = 10 ** 10\nfor l, r in zip(range(0, n - k + 1), range(k - 1, n)):\n time = x[r] if x[l] >= 0 else (-x[l] if x[r] <= 0 else (x[r] - x[l]) + min(-x[l], x[r]))\n if time < min_time:\n min_time = time\nprint(min_time)'] | ['Wrong Answer', 'Wrong Answer', 'Accepted'] | ['s130982299', 's535854981', 's451734543'] | [14568.0, 14564.0, 14380.0] | [79.0, 79.0, 78.0] | [734, 646, 300] |
p03274 | u309141201 | 2,000 | 1,048,576 | There are N candles placed on a number line. The i-th candle from the left is placed on coordinate x_i. Here, x_1 < x_2 < ... < x_N holds. Initially, no candles are burning. Snuke decides to light K of the N candles. Now, he is at coordinate 0. He can move left and right along the line with speed 1. He can also light a candle when he is at the same position as the candle, in negligible time. Find the minimum time required to light K candles. | ["N, K = map(int, input().split())\nx = list(map(int, input().split()))\nanswer = float('inf')\nfor l, r in zip(x, x[K - 1:]):\n print(l, r)\n cost = r - l + min(abs(l), abs(r))\n answer = cost if cost < answer else answer\n\nprint(answer)", "N, K = map(int, input().split())\nx = list(map(int, input().split()))\nanswer = float('inf')\nfor l, r in zip(x, x[K - 1 :]):\n print(l, r)\n cost = r - l + min(abs(l), abs(r))\n answer = cost if cost < answer else answer\n\nprint(answer)", "N, K = map(int, input().split())\nx = list(map(int, input().split()))\nanswer = float('inf')\nfor l, r in zip(x, x[K - 1:]):\n # print(l, r)\n cost = r - l + min(abs(l), abs(r))\n answer = cost if cost < answer else answer\n\nprint(answer)"] | ['Wrong Answer', 'Wrong Answer', 'Accepted'] | ['s265376017', 's318405043', 's990738063'] | [14228.0, 15020.0, 14224.0] | [129.0, 132.0, 71.0] | [238, 239, 240] |
p03274 | u314050667 | 2,000 | 1,048,576 | There are N candles placed on a number line. The i-th candle from the left is placed on coordinate x_i. Here, x_1 < x_2 < ... < x_N holds. Initially, no candles are burning. Snuke decides to light K of the N candles. Now, he is at coordinate 0. He can move left and right along the line with speed 1. He can also light a candle when he is at the same position as the candle, in negligible time. Find the minimum time required to light K candles. | ['n, k= map(int,input().split())\nx = list(map(int, input().split()))\nif 0 not in x:\n k += 1\n x.append(0)\n x = sorted(x)\nx = [abs(i) for i in x]\n\norig = x.index(0)\n\nans = float("inf")\nfor i in range(k):\n f = orig + i\n s = orig + i - k\n if (s >= 0) and (f <= n-1):\n temp1 = x[s]\n temp2 = x[f]\n ans = min([ans, 2*temp1+temp2, temp1+2*temp2])\n\nprint(ans)', 'n, k= map(int,input().split())\nx = list(map(int, input().split()))\nif 0 not in x:\n k += 1\n x.append(0)\n x = sorted(x)\nx = [abs(i) for i in x]\n\norig = x.index(0)\n\nans = float("inf")\nfor i in range(k):\n f = orig + i\n s = orig + i - k + 1\n if (s >= 0) and (f <= len(x)-1):\n temp1 = x[s]\n temp2 = x[f]\n ans = min([ans, 2*temp1+temp2, temp1+2*temp2])\n\nprint(ans)'] | ['Wrong Answer', 'Accepted'] | ['s052297749', 's546831571'] | [14224.0, 14384.0] | [97.0, 102.0] | [387, 396] |
p03274 | u325704929 | 2,000 | 1,048,576 | There are N candles placed on a number line. The i-th candle from the left is placed on coordinate x_i. Here, x_1 < x_2 < ... < x_N holds. Initially, no candles are burning. Snuke decides to light K of the N candles. Now, he is at coordinate 0. He can move left and right along the line with speed 1. He can also light a candle when he is at the same position as the candle, in negligible time. Find the minimum time required to light K candles. | ["N, K = map(int, input().split())\nx = list(map(int, input().split()))\n\npoint= len(x) - 1\nfor i, v in enumerate(x):\n if v >= 0:\n point = i\n break\n\nstart = max(0, point - K + 1)\nend = start + K - 1\n\nif x[point] != 0:\n start -= 1\n end -= 1\n \nans = float('inf')\n\nwhile True:\n if x[start] >= 0:\n time = x[end]\n elif x[end] <= 0:\n time = abs(x[start])\n elif abs(x[start]) <= x[end]:\n time = abs(x[start] * 2) + x[end]\n else:\n time = abs(x[start]) + (x[end] * 2)\n ans = min(ans, time)\n \n start += 1\n end += 1\n\n if start > point or end == len(x):\n break\n \nprint(ans)", "N, K = map(int, input().split())\nx = list(map(int, input().split()))\n\npoint= len(x) - 1\nfor i, v in enumerate(x):\n if v == 0:\n point = i\n break\n elif v > 0:\n point = i - 1\n break\n\nstart = max(0, point - K + 1)\nend = start + K - 1\n\nif x[point] != 0:\n point += 1\n \nans = float('inf')\n\nwhile True:\n if x[start] >= 0:\n time = x[end]\n elif x[end] <= 0:\n time = abs(x[start])\n elif abs(x[start]) <= x[end]:\n time = abs(x[start] * 2) + x[end]\n else:\n time = abs(x[start]) + (x[end] * 2)\n ans = min(ans, time)\n \n start += 1\n end += 1\n\n if start > point or end == len(x):\n break\n \nprint(ans)"] | ['Wrong Answer', 'Accepted'] | ['s290442806', 's359718820'] | [14480.0, 14480.0] | [101.0, 105.0] | [648, 687] |
p03274 | u332657092 | 2,000 | 1,048,576 | There are N candles placed on a number line. The i-th candle from the left is placed on coordinate x_i. Here, x_1 < x_2 < ... < x_N holds. Initially, no candles are burning. Snuke decides to light K of the N candles. Now, he is at coordinate 0. He can move left and right along the line with speed 1. He can also light a candle when he is at the same position as the candle, in negligible time. Find the minimum time required to light K candles. | ['n, k = map(int, input().split())\nX = list(map(int, input().split()))\n\nfor i in range(n):\n if X[i] > 0:\n over_zero = i\n break\nelse:\n over_zero = n\n\nmin_cost = 10**8\n\nif over_zero + k - 1 < n:\n min_cost = X[over_zero + k - 1]\n\nif over_zero - k >= 0:\n min_cost = min(X[over_zero - k], min_cost)\nfor i in range(0, k+1):\n \n if over_zero - i >= 0:\n minus_cost = -(X[over_zero - i])\n else:\n continue\n \n if over_zero + k - i - 1 < n:\n plus_cost = (X[over_zero + k - i - 1])\n else:\n continue\n cost = plus_cost + minus_cost + min(plus_cost, minus_cost) \n min_cost = min(cost, min_cost)\n\nprint(min_cost)', '\nn,k=map(int,input().split())\nx=sorted(list(map(int,input().split())))\nprint(min((min(abs(x[i])+abs(x[i+k-1]-x[i]),abs(x[i+k-1])+abs(x[i]-x[i+k-1]))) for i in range(n-k+1)))'] | ['Runtime Error', 'Accepted'] | ['s367227003', 's163984779'] | [14480.0, 14388.0] | [98.0, 90.0] | [716, 173] |
p03274 | u335038698 | 2,000 | 1,048,576 | There are N candles placed on a number line. The i-th candle from the left is placed on coordinate x_i. Here, x_1 < x_2 < ... < x_N holds. Initially, no candles are burning. Snuke decides to light K of the N candles. Now, he is at coordinate 0. He can move left and right along the line with speed 1. He can also light a candle when he is at the same position as the candle, in negligible time. Find the minimum time required to light K candles. | ['N, K = map(int, input().split())\nX = map(int, input().split())\n\nk = []\n# print(X)\n\nk0 = abs(X[0])\nfor n in range(0+1, K):\n k0 += X[n] - X[n-1]\n# print(k0)\nk.append(k0)\nfor i in range(1, len(X)-K+1):\n # print(i, i-1, i+K, i+K-1)\n ki = k[i-1] - (X[i] - X[i-1]) + (X[i+K-1] - X[i+K-2]) - abs(X[i-1]) + abs(X[i])\n k.append(ki)\nprint(min(k))\n', 'N, K = map(int, input().split())\nX = list(map(int, input().split()))\n\nk = []\n# print(X)\n\nk0 = abs(X[0])\nfor n in range(0+1, K):\n k0 += X[n] - X[n-1]\nk.append(k0)\nfor i in range(1, len(X)-K+1):\n ki = k[i-1] - (X[i] - X[i-1]) + (X[i+K-1] - X[i+K-2]) - abs(X[i-1]) + abs(X[i])\n k.append(ki)\n# print(min(k))\n\nl = []\nl0 = abs(X[N-1])\nfor n in range(N-1, N-K, -1):\n l0 += X[n] - X[n-1]\n# print(l0)\nl.append(l0)\nfor i in range(1, len(X)-K+1):\n # print(i, i-1, i+K, i+K-1)\n li = l[i-1] - (X[N-i] - X[N-i-1]) + (X[N-K-i+1] - X[N-K-i]) - abs(X[N-i]) + abs(X[N-i-1])\n # print(li)\n l.append(li)\nprint(min(min(k), min(l)))\n'] | ['Runtime Error', 'Accepted'] | ['s706809565', 's993263355'] | [11460.0, 14480.0] | [26.0, 190.0] | [349, 634] |
p03274 | u347640436 | 2,000 | 1,048,576 | There are N candles placed on a number line. The i-th candle from the left is placed on coordinate x_i. Here, x_1 < x_2 < ... < x_N holds. Initially, no candles are burning. Snuke decides to light K of the N candles. Now, he is at coordinate 0. He can move left and right along the line with speed 1. He can also light a candle when he is at the same position as the candle, in negligible time. Find the minimum time required to light K candles. | ["n, k = map(int, input().split())\nx = list(map(int, input().split()))\np = n\nfor i in range(n):\n if x[i] > 0:\n p = i\n break\nresult = float('inf')\nfor i in range(max(p - k, 0), min(k - p, k + 1)):\n if i == 0:\n result = min(result, x[p + k - 1])\n elif i == k:\n result = min(result, -x[p - k])\n else:\n l = x[p - i]\n r = x[p + (k - i) - 1]\n result = min(result, r - 2 * l, r * 2 - l)\nprint(result)\n", "n, k = map(int, input().split())\nx = list(map(int, input().split()))\np = n\nfor i in range(n):\n if x[i] > 0:\n p = i\n break\nresult = float('inf')\nfor i in range(k + 1):\n if p - i < 0 or p + k - i > n:\n continue\n if i == 0:\n result = min(result, x[p + k - 1])\n elif i == k:\n result = min(result, -x[p - k])\n else:\n l = x[p - i]\n r = x[p + (k - i) - 1]\n result = min(result, r - 2 * l, r * 2 - l)\nprint(result)\n"] | ['Runtime Error', 'Accepted'] | ['s950540348', 's458867878'] | [14480.0, 14564.0] | [119.0, 95.0] | [417, 436] |
p03274 | u349091349 | 2,000 | 1,048,576 | There are N candles placed on a number line. The i-th candle from the left is placed on coordinate x_i. Here, x_1 < x_2 < ... < x_N holds. Initially, no candles are burning. Snuke decides to light K of the N candles. Now, he is at coordinate 0. He can move left and right along the line with speed 1. He can also light a candle when he is at the same position as the candle, in negligible time. Find the minimum time required to light K candles. | ['import numpy as np\nimport bisect\nN,K=map(int,input().split())\nX=[int(i) for i in input().split()]\nmin_=10**10\nfor i in range(N-K+1):\n if X[i] == 0 or X[i+K-1] == 0:\n print(max(abs(X[i]),abs(X[i+K-1])))\n min_=min(min_,max(abs(X[i]),abs(X[i+K-1])))\n elif np.sign(X[i]) == np.sign(X[i+K-1]):\n print(max(abs(X[i]),abs(X[i+K-1])))\n min_=min(min_,max(abs(X[i]),abs(X[i+K-1])))\n else:\n print(abs(min(X[i],X[i+K-1]))*2+abs(max(X[i],X[i+K-1])))\n min_=min(min_,abs(min(X[i],X[i+K-1]))*2+abs(max(X[i],X[i+K-1])))\nprint(min_)', 'import numpy as np\nimport bisect\nN,K=map(int,input().split())\nX=[int(i) for i in input().split()]\nmin_=10**10\nfor i in range(N-K+1):\n #print(i,i+K-1)\n temp=min(abs(X[i])+abs(X[i]-X[i+K-1]),abs(X[i+K-1])+abs(X[i]-X[i+K-1]))\n min_=min(temp,min_)\nprint(min_)'] | ['Wrong Answer', 'Accepted'] | ['s834515153', 's074075113'] | [23092.0, 23084.0] | [547.0, 234.0] | [564, 264] |
p03274 | u350049649 | 2,000 | 1,048,576 | There are N candles placed on a number line. The i-th candle from the left is placed on coordinate x_i. Here, x_1 < x_2 < ... < x_N holds. Initially, no candles are burning. Snuke decides to light K of the N candles. Now, he is at coordinate 0. He can move left and right along the line with speed 1. He can also light a candle when he is at the same position as the candle, in negligible time. Find the minimum time required to light K candles. | ['import bisect\n\nN,K=map(int,input().split())\nX=list(map(int,input().split()))\n\nif 0 in X:\n K=K-1\n\nRight=[]\nLeft=[]\n \nfor x in X:\n if x>0:\n Right.append(x):\n else:\n Left=[abs(x)]+Left\n\nprint(Right)\nprint(Left)\n \n ', 'import bisect\n\nN,K=map(int,input().split())\nX=list(map(int,input().split()))\n\nif 0 in X:\n K=K-1\nans=[]\nRight=[]\nLeft=[]\n \nfor x in X:\n if x>0:\n Right.append(x)\n else:\n Left.append(abs(x))\n\nLeft.append(0)\nLeft.sort()\nRight=[0]+Right\n \nfor i in range(K+1):\n if i<=len(Right)-1 and K-i<=len(Left)-1:\n ans.append(min(Right[i],Left[K-i])*2+max(Right[i],Left[K-i]))\n\nif K==0:\n ans.append(0)\n\nprint(min(ans))\n'] | ['Runtime Error', 'Accepted'] | ['s118458244', 's245189786'] | [2940.0, 14660.0] | [18.0, 127.0] | [229, 420] |
p03274 | u369752439 | 2,000 | 1,048,576 | There are N candles placed on a number line. The i-th candle from the left is placed on coordinate x_i. Here, x_1 < x_2 < ... < x_N holds. Initially, no candles are burning. Snuke decides to light K of the N candles. Now, he is at coordinate 0. He can move left and right along the line with speed 1. He can also light a candle when he is at the same position as the candle, in negligible time. Find the minimum time required to light K candles. | ['def update():\n cost = list(map(abs, candles))\n min_cost_index = cost.index(min(cost))\n print(min_cost_index)\n start_index = max(0, min_cost_index - K)\n end_index = min(N, min_cost_index + K)\n new_candles = candles[start_index: end_index]\n return new_candles\n\ndef compute_cost(point_candles):\n if(point_candles[0] * point_candles[-1] >= 0):\n return max(abs(point_candles[0]), abs(point_candles[-1]))\n else:\n return point_candles[-1] - point_candles[0] + min(abs(point_candles[0]), abs(point_candles[-1])) \n\nN, K = list(map(int, input().strip().split(" ")))\ncandles = list(map(int, input().strip().split(" ")))\n\n\n\ncandles = update()\n\nN = len(candles)\nmin_cost = None\npatterns = N - K + 1\n\n\nfor start_index in range(patterns):\n cost = compute_cost(candles[start_index:start_index + K])\n if(min_cost == None or min_cost > cost):\n min_cost = cost\nprint(min_cost)', 'N, K = list(map(int, input().strip().split(" ")))\ncandles = input().strip()\nmin_cost_index = candles.count("-")\ncandles = list(map(int, candles.split(" ")))\n\ndef update():\n start_index = max(0, min_cost_index - K - 1)\n end_index = min(N, min_cost_index + K + 1)\n new_candles = candles[start_index: end_index]\n return new_candles\n\ndef compute_cost(point_candles):\n if(point_candles[0] * point_candles[-1] >= 0):\n return max(abs(point_candles[0]), abs(point_candles[-1]))\n else:\n return point_candles[-1] - point_candles[0] + min(abs(point_candles[0]), abs(point_candles[-1])) \n \nstart_time = time.perf_counter()\ncandles = update()\n\nN = len(candles)\nmin_cost = None\npatterns = N - K + 1\n\n\nfor start_index in range(patterns):\n cost = compute_cost(candles[start_index:start_index + K])\n if(min_cost == None or min_cost > cost):\n min_cost = cost\nprint(min_cost)', 'def compute_cost(point_candles):\n if(point_candles[0] * point_candles[-1] >= 0):\n return max(abs(point_candles[0]), abs(point_candles[-1]))\n else:\n return abs(point_candles[0]) + abs(point_candles[-1])\n\nN, K = list(map(int, input().strip().split(" ")))\ncandles = list(map(int, input().strip().split(" ")))\n\npatterns = N - K + 1\n\nmin_cost = None\n\nfor start_index in range(patterns):\n cost = compute_cost(candles[start_index:start_index + K])\n print(cost)\n if(min_cost == None or min_cost > cost):\n min_cost = cost\nprint(min_cost)', 'N, K = list(map(int, input().strip().split(" ")))\ncandles = input().strip()\nmin_cost_index = candles.count("-")\ncandles = list(map(int, candles.split(" ")))\n\ndef update():\n start_index = max(0, min_cost_index - K - 1)\n end_index = min(N, min_cost_index + K + 1)\n new_candles = candles[start_index: end_index]\n return new_candles\n\ndef compute_cost(start_index):\n start_point = candles[start_index]\n end_point = candles[start_index + K - 1]\n if(start_point * end_point >= 0):\n return max(abs(start_point), abs(end_point))\n else:\n return end_point - start_point + min(-start_point, end_point) \n\ncandles = update()\n\nN = len(candles)\nmin_cost = compute_cost(0)\npatterns = N - K + 1\n\nfor start_index in range(patterns):\n cost = compute_cost(start_index)\n if(min_cost > cost):\n min_cost = cost\nprint(min_cost)'] | ['Wrong Answer', 'Runtime Error', 'Wrong Answer', 'Accepted'] | ['s560894493', 's749633715', 's751214185', 's978889930'] | [14480.0, 15492.0, 14224.0, 15616.0] | [2104.0, 43.0, 2104.0, 72.0] | [911, 903, 564, 853] |
p03274 | u370721525 | 2,000 | 1,048,576 | There are N candles placed on a number line. The i-th candle from the left is placed on coordinate x_i. Here, x_1 < x_2 < ... < x_N holds. Initially, no candles are burning. Snuke decides to light K of the N candles. Now, he is at coordinate 0. He can move left and right along the line with speed 1. He can also light a candle when he is at the same position as the candle, in negligible time. Find the minimum time required to light K candles. | ['import math\nN, K = map(int, input().split())\nx = list(map(int, input().split()))\nfor i in range(N):\n if x[i] == 0:\n p, m = i, i+1\n break\n elif x[i] > 0:\n p, m = i, i\n break\n \nif (x[0]<0) and (x[-1]>0):\n pls = x[p:]\n mns = x[:m]\n ans = math.inf\n\n for i in range(len(pls)):\n if i < K-1:\n if pls[0] == 0:\n n = K - i\n else:\n n = K - i - 1\n if len(mns) >= n:\n tmp = 2*abs(mns[-n]) + pls[i]\n ans = min(ans, tmp)\n if i == K-1:\n ans = min(ans, pls[i])\n break\n \n for i in range(len(mns)):\n m = len(mns)-i\n if m < K:\n if pls[0] == 0:\n n = K - m\n else:\n n = K - m - 1\n if len(pls) > n:\n tmp = 2*pls[n] + abs(mns[-m])\n print(i, tmp)\n ans = min(ans, tmp)\n if m == K:\n ans = min(ans, abs(mns[i]))\n \nelif x[0] >= 0:\n ans = x[K-1]\n \nelse:\n ans = abs(x[-K])\n \nprint(ans)', 'import math\nN, K = map(int, input().split())\nx = list(map(int, input().split()))\nfor i in range(N):\n if x[i] == 0:\n p, m = i, i+1\n break\n elif x[i] > 0:\n p, m = i, i\n break\n \nif (x[0]<0) and (x[-1]>0):\n pls = x[p:]\n mns = x[:m]\n ans = math.inf\n\n for i in range(len(pls)):\n if i < K-1:\n if pls[0] == 0:\n n = K - i\n else:\n n = K - i - 1\n if len(mns) >= n:\n tmp = 2*abs(mns[-n]) + pls[i]\n ans = min(ans, tmp)\n if i == K-1:\n ans = min(ans, pls[i])\n break\n \n for i in range(len(mns)):\n m = len(mns)-i\n if m < K:\n if pls[0] == 0:\n n = K - m\n else:\n n = K - m - 1\n if len(pls) > n:\n tmp = 2*pls[n] + abs(mns[-m])\n ans = min(ans, tmp)\n if m == K:\n ans = min(ans, abs(mns[i]))\n \nelif x[0] >= 0:\n ans = x[K-1]\n \nelse:\n ans = abs(x[-K])\n \nprint(ans)'] | ['Wrong Answer', 'Accepted'] | ['s157177432', 's677222363'] | [19868.0, 20196.0] | [154.0, 126.0] | [908, 886] |
p03274 | u380524497 | 2,000 | 1,048,576 | There are N candles placed on a number line. The i-th candle from the left is placed on coordinate x_i. Here, x_1 < x_2 < ... < x_N holds. Initially, no candles are burning. Snuke decides to light K of the N candles. Now, he is at coordinate 0. He can move left and right along the line with speed 1. He can also light a candle when he is at the same position as the candle, in negligible time. Find the minimum time required to light K candles. | ['n, k = map(int, input().split())\nX = list(map(int, input().split()))\n\ncount_0 = X.count(0)\n\nif k <= count_0:\n print(0)\n exit()\n\nk -= count_0\n\nneg = [x for x in X if x < 0]\npos = [x for x in X if x > 0]\n\nneg_count = len(neg)\npos_count = len(pos)\n\nif not neg:\n print(pos[k-1])\n exit()\nif not pos:\n \tprint(neg[-k])\n exit()\n\nres = []\nfor left in range(1, min(neg_count, k)):\n time1 = neg[-left]\n right = k - left - 1\n if right >= pos_count:\n continue\n elif right < 0:\n res.append(abs(time1))\n else:\n time2 = pos[right]\n res.append(time2-time1*2)\n\nfor right in range(min(pos_count, k)):\n time1 = pos[right]\n left = k - right - 1\n if left >= neg_count:\n continue\n elif left <= 0:\n res.append(abs(time1))\n else:\n time2 = neg[-left]\n res.append(time1*2-time2)\n\n\nprint(min(res))', 'n, k = map(int, input().split())\nX = list(map(int, input().split()))\n\ncount_0 = X.count(0)\n\nif k <= count_0:\n print(0)\n exit()\n\nk -= count_0\n\nneg = [x for x in X if x < 0]\npos = [x for x in X if x > 0]\n\nneg_count = len(neg)\npos_count = len(pos)\n\nif not neg:\n print(pos[k-1])\n exit()\n\nres = []\nfor left in range(1, min(neg_count, k)):\n time1 = neg[-left]\n right = k - left - 1\n if right >= pos_count:\n continue\n elif right < 0:\n res.append(abs(time1))\n else:\n time2 = pos[right]\n res.append(time2-time1*2)\n\nfor right in range(min(pos_count, k)):\n time1 = pos[right]\n left = k - right - 1\n if left >= neg_count:\n continue\n elif left <= 0:\n res.append(abs(time1))\n else:\n time2 = neg[-left]\n res.append(time1*2-time2)\n', 'n, k = map(int, input().split())\nX = list(map(int, input().split()))\n\nans = []\nfor i in range(n-k+1):\n left = X[i]\n right = X[i+k-1]\n if left * right < 0:\n result = min(abs(left), abs(right)) * 2 + max(abs(left), abs(right))\n else:\n result = max(abs(left), abs(right))\n ans.append(result)\n\nprint(min(ans))'] | ['Runtime Error', 'Wrong Answer', 'Accepted'] | ['s507625162', 's796914978', 's907491887'] | [3064.0, 14480.0, 14568.0] | [17.0, 113.0, 100.0] | [871, 813, 334] |
p03274 | u383450070 | 2,000 | 1,048,576 | There are N candles placed on a number line. The i-th candle from the left is placed on coordinate x_i. Here, x_1 < x_2 < ... < x_N holds. Initially, no candles are burning. Snuke decides to light K of the N candles. Now, he is at coordinate 0. He can move left and right along the line with speed 1. He can also light a candle when he is at the same position as the candle, in negligible time. Find the minimum time required to light K candles. | ['n,k=map(int,input().split())\ncandle=list(map(int,input().split()))\ncom=list(itertools.product(["1","0"], repeat=n))\nans=2000000000\nfor i in range(n-k):\n if candle[i]<0 and candle[i+k-1]>0:\n temp=min(abs(candle[i]), candle[i+k-1])*2+max(abs(candle[i]), candle[i+k-1])\n else:\n temp=abs(candle[i+k-1]-candle[i])\n ans=min(temp, ans)\nprint(ans)', 'import itertools\nimport collections\nn,k=map(int,input().split())\ncandle=list(map(int,input().split()))\ncom=list(itertools.product([1,0], repeat=n))\nans=200000000\nfor i in range(2**n):\n count=collections.Counter(com[i])\n if count[1]==k:\n begin=0\n end=0\n cnt=0\n temp=0\n print(\n for j in range(n):\n if com[i][j]==1:\n cnt+=1\n if cnt==1:\n start=candle[j]\n elif cnt==k:\n end=candle[j]\n break;\n if start>=0:\n temp=abs(end)\n if temp<ans:\n ans=temp\n if end<=0:\n temp=abs(start)\n if temp<ans:\n ans=temp\n else:\n temp=min(abs(start), end)*2+max(abs(start), end)\n if temp<ans:\n ans=temp\nprint(ans)', 'n,k=map(int,input().split())\ncandle=list(map(int,input().split()))\nans=2000000000\nfor i in range(n-k+1):\n if candle[i]<0 and candle[i+k-1]>0:\n temp=min(abs(candle[i]), candle[i+k-1])*2+max(abs(candle[i]), candle[i+k-1])\n elif candle[i+k-1]<=0:\n temp=abs(candle[i])\n elif candle[i]>=0:\n temp=candle[i+k-1]\n ans=min(temp, ans)\nprint(ans)'] | ['Runtime Error', 'Runtime Error', 'Accepted'] | ['s077514805', 's634571288', 's427730717'] | [14384.0, 2940.0, 14844.0] | [42.0, 17.0, 108.0] | [348, 717, 348] |
p03274 | u384679440 | 2,000 | 1,048,576 | There are N candles placed on a number line. The i-th candle from the left is placed on coordinate x_i. Here, x_1 < x_2 < ... < x_N holds. Initially, no candles are burning. Snuke decides to light K of the N candles. Now, he is at coordinate 0. He can move left and right along the line with speed 1. He can also light a candle when he is at the same position as the candle, in negligible time. Find the minimum time required to light K candles. | ['N, K=map(int, input().split())\nx = list(map(int, input().split()))\nans = pow(10, 10)\nfor i in range(N-K+1):\n temp1 = abs(x[i]) + abs(x[i]-x[i+K-1])\n #temp2 = abs(x[i+K-1]) + abs(x[i]-x[i+K-1])\n ans = min(ans, temp1, temp2)\nprint(ans)\n', 'N, K = map(int, input().split())\nx = list(map(int, input().split()))\nans = pow(10, 10)\nfor i in range(K, len(x)):\n ans = min(ans, abs(x[i-1]) + abs(x[i-1] - x[i-K]))\nprint(ans)', 'N, K = map(int, input().split())\na = list(map(int, input().split()))\nans = 10 ** 9\nfor i in range(len(a) - K + 1):\n l = a[i]\n r = a[i + K - 1]\n ans = min(ans, abs(l) + abs(r - l), abs(r) + abs(l - r))\nprint(ans)'] | ['Runtime Error', 'Wrong Answer', 'Accepted'] | ['s783696233', 's960393682', 's342762693'] | [14252.0, 14252.0, 14252.0] | [43.0, 74.0, 85.0] | [243, 177, 214] |
p03274 | u386819480 | 2,000 | 1,048,576 | There are N candles placed on a number line. The i-th candle from the left is placed on coordinate x_i. Here, x_1 < x_2 < ... < x_N holds. Initially, no candles are burning. Snuke decides to light K of the N candles. Now, he is at coordinate 0. He can move left and right along the line with speed 1. He can also light a candle when he is at the same position as the candle, in negligible time. Find the minimum time required to light K candles. | ['n,k = (int(_) for _ in input().split())\nx = [int(_) for _ in input().split()]\n', '#!/usr/bin/env python3\nimport sys\n\n\ndef solve(N: int, K: int, x: "List[int]"):\n\n ans = 10000000000000000000\n\n\n al = []\n\n for i in range(N-K+1):\n if(x[i] <= 0 <= x[i+K-1]):\n w = abs(x[i+K-1]) + abs(x[i]) + min(abs(x[i+K-1]), abs(x[i]))\n else:\n w = max(abs(x[i+K-1]),abs(x[i]))\n \n al = [x[i], x[i+K-1]]\n ans = min(ans, w)\n \n if(not al):\n print(0)\n else:\n print(ans)\n\n return\n\n\n# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools (tips: You use the default template now. You can remove this line by using your custom template)\ndef main():\n def iterate_tokens():\n for line in sys.stdin:\n for word in line.split():\n yield word\n tokens = iterate_tokens()\n N = int(next(tokens)) # type: int\n K = int(next(tokens)) # type: int\n x = [ int(next(tokens)) for _ in range(N) ] # type: "List[int]"\n solve(N, K, x)\n\nif __name__ == \'__main__\':\n main()\n'] | ['Wrong Answer', 'Accepted'] | ['s416174286', 's999617806'] | [14252.0, 15148.0] | [46.0, 117.0] | [78, 1006] |
p03274 | u388323466 | 2,000 | 1,048,576 | There are N candles placed on a number line. The i-th candle from the left is placed on coordinate x_i. Here, x_1 < x_2 < ... < x_N holds. Initially, no candles are burning. Snuke decides to light K of the N candles. Now, he is at coordinate 0. He can move left and right along the line with speed 1. He can also light a candle when he is at the same position as the candle, in negligible time. Find the minimum time required to light K candles. | ["n, k = map(int,input().split())\n\narr = list(map(int, input().split()))\n\nans = float('inf')\n\nfor i in range(n - k + 1):\n\tif arr[i] * arr[k + i -1] >= 0:\n\t\ttmp = max(abs(arr[i]), abs(arr[k + i -1]))\n\t\tprint(tmp)\n\telse:\n\t\ttmp = abs(arr[i]) + abs(arr[k + i -1]) + min(abs(arr[i]), abs(arr[k + i -1]))\n\tans = min(ans, tmp)\n\nprint(ans)\n\t\t", "n, k = map(int,input().split())\n\narr = list(map(int, input().split()))\n\nans = float('inf')\n\nfor i in range(n - k + 1):\n\tif arr[i] * arr[k + i -1] >= 0:\n\t\ttmp = max(abs(arr[i]), abs(arr[k + i -1]))\n\telse:\n\t\ttmp = abs(arr[i]) + abs(arr[k + i -1]) + min(abs(arr[i]), abs(arr[k + i -1]))\n\tans = min(ans, tmp)\n\nprint(ans)\n\t\t"] | ['Wrong Answer', 'Accepted'] | ['s784347813', 's940201530'] | [14384.0, 14568.0] | [135.0, 104.0] | [332, 319] |
p03274 | u408620326 | 2,000 | 1,048,576 | There are N candles placed on a number line. The i-th candle from the left is placed on coordinate x_i. Here, x_1 < x_2 < ... < x_N holds. Initially, no candles are burning. Snuke decides to light K of the N candles. Now, he is at coordinate 0. He can move left and right along the line with speed 1. He can also light a candle when he is at the same position as the candle, in negligible time. Find the minimum time required to light K candles. | ["import sys\nimport bisect\ninput = sys.stdin.readline\nN, K = [int(x) for x in input().strip().split()]\nX = [int(x) for x in input().strip().split()]\nb = 1\nif X.count(0) == 0:\n X.insert(bisect.bisect(X, 0), 0)\n b = 0\n\ns = X.index(0)\nans = float('INF')\nprint(X)\nfor i in range(1, K + 1):\n if s + i < len(X):\n t_ans = X[s + i]\n if i + b == K:\n ans = min(ans, t_ans)\n break\n else:\n if s - (K - i) < 0:\n continue\n t_ans += X[s + i]\n ans = min(ans, t_ans - X[s - (K - i)])\n else:\n break\n\nfor i in range(1, K + 1):\n if s - i >= 0:\n t_ans = - X[s - i]\n if i + b == K:\n ans = min(ans, t_ans)\n break\n else:\n if s + (K - i) >= len(X):\n continue\n t_ans += - X[s - i]\n ans = min(ans, t_ans + X[s + (K - i)])\n\nif ans == float('INF'):\n ans = 0\nprint(ans)", "import sys\nimport bisect\ninput = sys.stdin.readline\nN, K = [int(x) for x in input().strip().split()]\nX = [int(x) for x in input().strip().split()]\nb = 1\nif X.count(0) == 0:\n X.insert(bisect.bisect(X, 0), 0)\n b = 0\n\ns = X.index(0)\nans = float('INF')\nprint(X)\nfor i in range(1, K + 1):\n if s + i < len(X):\n t_ans = X[s + i]\n if i + b == K:\n ans = min(ans, t_ans)\n print()\n break\n else:\n if s - (K - i) < 0:\n continue\n t_ans += X[s + i]\n ans = min(ans, t_ans - X[s - (K - i)])\n else:\n break\n\nfor i in range(1, K + 1):\n if s - i >= 0:\n t_ans = - X[s - i]\n if i + b == K:\n ans = min(ans, t_ans)\n print()\n break\n else:\n if s + (K - i) >= len(X):\n continue\n t_ans += - X[s - i]\n ans = min(ans, t_ans + X[s + (K - i)])\n\nif ans == float('INF'):\n ans = 0\nprint(ans)", "import sys\nimport bisect\ninput = sys.stdin.readline\nN, K = [int(x) for x in input().strip().split()]\nX = [int(x) for x in input().strip().split()]\nb = 1\nif X.count(0) == 0:\n X.insert(bisect.bisect(X, 0), 0)\n b = 0\n\ns = X.index(0)\nans = float('INF')\nfor i in range(1, K + 1):\n if s + i < len(X):\n t_ans = X[s + i]\n if i + b == K:\n ans = min(ans, t_ans)\n break\n else:\n if s - (K - i) < 0:\n continue\n t_ans += X[s + i]\n ans = min(ans, t_ans - X[s - (K - i)])\n else:\n break\n\nfor i in range(1, K + 1):\n if s - i >= 0:\n t_ans = - X[s - i]\n if i + b == K:\n ans = min(ans, t_ans)\n break\n else:\n if s + (K - i) >= len(X):\n continue\n t_ans += - X[s - i]\n ans = min(ans, t_ans + X[s + (K - i)])\n\nif ans == float('INF'):\n ans = 0\nprint(ans)"] | ['Wrong Answer', 'Wrong Answer', 'Accepted'] | ['s000268952', 's032626061', 's264404969'] | [14792.0, 14232.0, 14316.0] | [157.0, 162.0, 150.0] | [944, 984, 935] |
p03274 | u417794477 | 2,000 | 1,048,576 | There are N candles placed on a number line. The i-th candle from the left is placed on coordinate x_i. Here, x_1 < x_2 < ... < x_N holds. Initially, no candles are burning. Snuke decides to light K of the N candles. Now, he is at coordinate 0. He can move left and right along the line with speed 1. He can also light a candle when he is at the same position as the candle, in negligible time. Find the minimum time required to light K candles. | ["N, K = map(int, input().split())\narr = list(map(int, input().split()))\n\nans = float('inf')\nfor i in range(N+1-K):\n print(arr[i],arr[i+K-1])\n if arr[i]<= 0 and arr[i+K-1]>0:\n preans = min(abs(arr[i]*2) + arr[i+K-1], abs(arr[i]) + arr[i+K-1]*2)\n elif arr[i]<=0 and arr[i+K-1]<=0:\n preans = abs(arr[i])\n elif arr[i]>=0 and arr[i+K-1]>=0:\n preans = arr[i+K-1]\n ans = min(ans,preans)\n\nprint(ans)", "N, K = map(int, input().split())\narr = list(map(int, input().split()))\n\nans = float('inf')\nfor i in range(N+1-K):\n if arr[i]<= 0 and arr[i+K-1]>0:\n preans = min(abs(arr[i]*2) + arr[i+K-1], abs(arr[i]) + arr[i+K-1]*2)\n elif arr[i]<=0 and arr[i+K-1]<=0:\n preans = abs(arr[i])\n elif arr[i]>=0 and arr[i+K-1]>=0:\n preans = arr[i+K-1]\n ans = min(ans,preans)\n\nprint(ans)"] | ['Wrong Answer', 'Accepted'] | ['s818594507', 's444998677'] | [14844.0, 14564.0] | [173.0, 104.0] | [426, 397] |
p03274 | u426764965 | 2,000 | 1,048,576 | There are N candles placed on a number line. The i-th candle from the left is placed on coordinate x_i. Here, x_1 < x_2 < ... < x_N holds. Initially, no candles are burning. Snuke decides to light K of the N candles. Now, he is at coordinate 0. He can move left and right along the line with speed 1. He can also light a candle when he is at the same position as the candle, in negligible time. Find the minimum time required to light K candles. | ['n, k = map(int, input().split())\nx = list(map(int, input().split()))\nans = 10**9\nfor i in range(k-1, n):\n dR = abs(x[i]) + abs(x[i] - x[i-k+1])\n dL = abs(x[i-k+1]) + abs(x[i] - x[i-k+1])\n ans = min(ans, dR, dL)\n print(i, dR, dL)\nprint(ans)', 'n, k = map(int, input().split())\nx = list(map(int, input().split()))\nans = 10**9\nfor i in range(k-1, n):\n dR = abs(x[i]) + abs(x[i] - x[i-k+1])\n dL = abs(x[i-k+1]) + abs(x[i] - x[i-k+1])\n ans = min(ans, dR, dL)\nprint(ans)'] | ['Wrong Answer', 'Accepted'] | ['s696216361', 's743228633'] | [14384.0, 14224.0] | [194.0, 98.0] | [243, 224] |
p03274 | u427344224 | 2,000 | 1,048,576 | There are N candles placed on a number line. The i-th candle from the left is placed on coordinate x_i. Here, x_1 < x_2 < ... < x_N holds. Initially, no candles are burning. Snuke decides to light K of the N candles. Now, he is at coordinate 0. He can move left and right along the line with speed 1. He can also light a candle when he is at the same position as the candle, in negligible time. Find the minimum time required to light K candles. | ['N, K = map(int, input().split())\nx_list = list(map(int, input().split()))\n\nresult = []\nfor i in range(N-K):\n start = i\n end = i + K -1\n result.append(abs(x_list[start] + abs(x_list[end] - x_list[start])))\n result.append(abs(x_list[end]) + abs(x_list[end] - x_list[start] ))\nprint(min(result))', 'N, K = map(int, input().split())\nx_list = list(map(int, input().split()))\n\nresult = []\nfor i in range(N-(K-1)):\n start = i\n end = i + (K -1)\n result.append(abs(x_list[start] + abs(x_list[end] - x_list[start])))\n result.append(abs(x_list[end]) + abs(x_list[end] - x_list[start] ))\nprint(min(result))', 'N, K = map(int, input().split())\nx_list = list(map(int, input().split()))\n\nresult = []\nfor i in range(N-K):\n start = i\n end = i + K \n result.append(abs(x_list[start] + abs(x_list[end] - x_list[start])))\n result.append(abs(x_list[end]) + abs(x_list[end] - x_list[start] ))\nprint(min(result))', 'N, K = map(int, input().split())\nx_list = list(map(int, input().split()))\n\nif x_list[0] >= 0:\n for i in range(N - K):\n x_list.pop(-1)\n print(max(x_list))\n\nelse:\n for i in range(N-K):\n p = abs(x_list[-1] - x_list[-2])\n n = abs(x_list[0] - x_list[1])\n if p > n:\n x_list.pop(-1)\n else:\n x_list.pop(0)\n print(x_list)\n if x_list[0] >= 0:\n print(max(x_list))\n else:\n print(x_list[-1] - x_list[0]*2)', 'N, K = map(int, input().split())\nx_list = list(map(int, input().split()))\n\nresult = []\nfor i in range(N-(K-1)):\n start = i\n end = i + (K -1)\n result.append(abs(x_list[start]) + abs(x_list[end] - x_list[start]))\n result.append(abs(x_list[end]) + abs(x_list[end] - x_list[start]))\nprint(min(result))'] | ['Runtime Error', 'Wrong Answer', 'Runtime Error', 'Wrong Answer', 'Accepted'] | ['s052467542', 's313040621', 's449962042', 's717507149', 's728026986'] | [14392.0, 14384.0, 14252.0, 14780.0, 14568.0] | [91.0, 96.0, 91.0, 1215.0, 90.0] | [305, 311, 303, 481, 309] |
p03274 | u439176910 | 2,000 | 1,048,576 | There are N candles placed on a number line. The i-th candle from the left is placed on coordinate x_i. Here, x_1 < x_2 < ... < x_N holds. Initially, no candles are burning. Snuke decides to light K of the N candles. Now, he is at coordinate 0. He can move left and right along the line with speed 1. He can also light a candle when he is at the same position as the candle, in negligible time. Find the minimum time required to light K candles. | ['N, K = [int(item) for item in input().split()]\ncandles = []\nfor item in input().split():\n if int(item) == 0:\n K -= 1\n continue\n candles.append(int(item))\nK = max(K-1, 0) \nprint(K)\nl = []\nfor i, candle in enumerate(candles):\n sign = candle > 0\n s = 1 if sign else -1\n ik = i-K if sign else i+K\n if ik > N or ik < 0:\n continue\n if (candles[ik] > 0) == sign:\n l.append(candle * s)\n else:\n l.append(candle * s + candles[ik] * -2 * s)\nif len(l) == 0:\n l.append(0)\nl.sort()\nprint(l[0])', 'N, K = [int(item) for item in input().split()]\ncandles = []\nfor item in input().split():\n if int(item) == 0:\n K -= 1\n continue\n candles.append(int(item))\nK = max(K-1, 0) \nprint(K)\nl = []\nfor i, candle in enumerate(candles):\n sign = candle > 0\n s = 1 if sign else -1\n ik = i-K if sign else i+K\n if ik > N or ik < 0:\n continue\n if (candles[ik] > 0) == sign:\n l.append(candle * s)\n else:\n l.append(candle * s + candles[ik] * -2 * s)\nif len(l) == 0:\n l.append(0)\nl.sort()\nprint(l[0])', 'N, K = [int(item) for item in input().split()]\ncandles = [int(item) for item in input().split()]\nans = []\nfor i in range(N-K+1):\n l, r = i, i+K-1\n ans.append(abs(candles[l]) + abs(candles[l] - candles[r]))\n ans.append(abs(candles[r]) + abs(candles[r] - candles[l]))\nans.sort()\nprint(ans[0])'] | ['Runtime Error', 'Runtime Error', 'Accepted'] | ['s429714710', 's966368228', 's987802691'] | [14920.0, 14612.0, 14224.0] | [171.0, 168.0, 109.0] | [503, 503, 293] |
p03274 | u442810826 | 2,000 | 1,048,576 | There are N candles placed on a number line. The i-th candle from the left is placed on coordinate x_i. Here, x_1 < x_2 < ... < x_N holds. Initially, no candles are burning. Snuke decides to light K of the N candles. Now, he is at coordinate 0. He can move left and right along the line with speed 1. He can also light a candle when he is at the same position as the candle, in negligible time. Find the minimum time required to light K candles. | ['N, K = map(int, input().split())\nx = list(map(int, input().split()))\n\ncount_m = 0\ncount_p = 0\nfor i in range(N):\n if x[i] > 0:\n count_m = i\n count_p = N-i\n break\n elif x[i] == 0:\n count_m = i\n count_p = N-i-1\n K -= 1\n N -= 1\n x.remove(x[i])\n break\nif count_m == 0 and count_p == 0:\n count_m = N\n\nans = 0\n \n\ny = K\nz = K - y\nfor j in range(1, y):\n #if count_m-j>0 and count_m+y-1-j<N-1:\n if True:\n\n print(j)\n\n print(x[count_m+y-1-j],x[count_m-j] ,x[count_m-1])\n\n\n\nif count_m >= 1 and N-K>0:\n\n tmp = min(x[count_m+y-1-j]-x[count_m-j] *2\n for j in range(1, y) if count_m-j>0 and count_m+y-1-j<N-1)\n tmp2 = min(x[count_m+y-1-j]*2-x[count_m-j]\n for j in range(1, y) if count_m-j>0 and count_m+y-1-j<N-1)\nelse:\n tmp = tmp2 = 1000000000\n\nif N==0:\n ans = 0\n\nelif count_p>=K:\n # print(y, "1chi")\n ans = min(tmp, tmp2, x[count_m+min(y, count_p)-1])\nelif count_m>=K:\n #print("ni")\n ans = min(tmp, tmp2, -x[count_m-K])\nelse:\n # print("san")\n ans = min(tmp, tmp2)\n\n\nprint(ans)\n', 'N, K = map(int, input().split())\nx = list(map(int, input().split()))\n\ncount_m = 0\ncount_p = 0\nfor i in range(N):\n if x[i] > 0:\n count_m = i\n count_p = N-i\n break\n elif x[i] == 0:\n count_m = i\n count_p = N-i-1\n K -= 1\n N -= 1\n break\nif count_m == 0 and count_p == 0:\n count_m = N\n\nans = 0\n\ny = K\nz = K - y\n\n# for j in range(1, y):\n# if count_m-j>0 and count_m+y-1-j<N-1:\n# print(j)\n# print(x[count_m+y-1-j],x[count_m-j] ,x[count_m-1])\n\nif count_m >= 1:\n tmp = min(x[count_m+y-1-j]-x[count_m-j] *2\n for j in range(1, y) if count_m-j>0 and count_m+y-1-j<N-1)\n tmp2 = min(x[count_m+y-1-j]*2-x[count_m-j] \n for j in range(1, y) if count_m-j>0 and count_m+y-1-j<N-1)\nelse:\n tmp = tmp2 = 1000000000\n#print(tmp, tmp2, x[count_m:y], -x[count_m-min(y, count_m)])\n\n#print("-----------------")\n#print(count_m, count_p)\nif count_p>=K:\n # print(y, "1chi")\n ans = min(tmp, tmp2, x[count_m+min(y, count_p)])\nelif count_m>=K:\n #print("ni")\n ans = min(tmp, tmp2, -x[count_m-K])\nelse:\n # print("san")\n ans = min(tmp, tmp2)\n \n\nprint(ans)\n', 'N, K = map(int, input().split())\nx = list(map(int, input().split()))\n\ncount_m = 0\ncount_p = 0\nfor i in range(N):\n if x[i] > 0:\n count_m = i\n count_p = N-i\n break\n elif x[i] == 0:\n count_m = i\n count_p = N-i-1\n K -= 1\n N -= 1\n x = x.remove(x[i])\n break\nif count_m == 0 and count_p == 0:\n count_m = N\n\nans = 0\n \n\ny = K\nz = K - y\nfor j in range(1, y):\n #if count_m-j>0 and count_m+y-1-j<N-1:\n if True:\n\n print(j)\n\n print(x[count_m+y-1-j],x[count_m-j] ,x[count_m-1])\n\n\n\nif count_m >= 1:\n tmp = min(x[count_m+y-1-j]-x[count_m-j] *2 for j in range(1, y) if count_m-j>=0 and count_m+y-1-j<N)\n tmp2 = min(x[count_m+y-1-j]*2-x[count_m-j] for j in range(1, y) if count_m-j>=0 and count_m+y-1-j<N)\nelse:\n tmp = tmp2 = 1000000000\n\nif N==0:\n ans = 0\n\nelif count_p>=K:\n # print(y, "1chi")\n ans = min(tmp, tmp2, x[count_m+min(y, count_p)-1])\nelif count_m>=K:\n #print("ni")\n ans = min(tmp, tmp2, -x[count_m-K])\nelse:\n # print("san")\n ans = min(tmp, tmp2)\n\n\nprint(ans)\n', 'N, K = map(int, input().split())\nx = list(map(int, input().split()))\n\ncount_m = 0\ncount_p = 0\nfor i in range(N):\n if x[i] > 0:\n count_m = i\n count_p = N-i\n break\n elif x[i] == 0:\n count_m = i\n count_p = N-i-1\n K -= 1\n N -= 1\n x.remove(x[i])\n break\nif count_m == 0 and count_p == 0:\n count_m = N\n\nans = 0\n \n\ny = K\nz = K - y\nfor j in range(1, y):\n #if count_m-j>0 and count_m+y-1-j<N-1:\n if True:\n\n print(j)\n\n print(x[count_m+y-1-j],x[count_m-j] ,x[count_m-1])\n\n\n\nif count_m >= 1:\n tmp = min(x[count_m+y-1-j]-x[count_m-j] *2 for j in range(1, y) if count_m-j>=0 and count_m+y-1-j<N)\n tmp2 = min(x[count_m+y-1-j]*2-x[count_m-j] for j in range(1, y) if count_m-j>=0 and count_m+y-1-j<N)\nelse:\n tmp = tmp2 = 1000000000\n\nif N==0:\n ans = 0\n\nelif count_p>=K:\n # print(y, "1chi")\n ans = min(tmp, tmp2, x[count_m+min(y, count_p)-1])\nelif count_m>=K:\n #print("ni")\n ans = min(tmp, tmp2, -x[count_m-K])\nelse:\n # print("san")\n ans = min(tmp, tmp2)\n\n\nprint(ans)\n', 'N, K = map(int, input().split())\nx = list(map(int, input().split()))\n\ncount_m = 0\ncount_p = 0\nfor i in range(N):\n if x[i] > 0:\n count_m = i\n count_p = N-i\n break\n elif x[i] == 0:\n count_m = i\n count_p = N-i-1\n K -= 1\n N -= 1\n x.remove(x[i])\n break\nif count_m == 0 and count_p == 0:\n count_m = N\n\nans = 0\n \n\ny = K\nz = K - y\n# for j in range(1, y):\n# if count_m-j>0 and count_m+y-1-j<N-1:\n\n# print(j)\n\n# print(x[count_m+y-1-j],x[count_m-j] ,x[count_m-1])\n\n\n\nif count_m >= 1:\n\n tmp = min(x[count_m+y-1-j]-x[count_m-j] *2\n for j in range(1, y) if count_m-j>0 and count_m+y-1-j<N-1)\n tmp2 = min(x[count_m+y-1-j]*2-x[count_m-j]\n for j in range(1, y) if count_m-j>0 and count_m+y-1-j<N-1)\nelse:\n tmp = tmp2 = 1000000000\n\nif count_p>=K:\n # print(y, "1chi")\n ans = min(tmp, tmp2, x[count_m+min(y, count_p)-1])\nelif count_m>=K:\n #print("ni")\n ans = min(tmp, tmp2, -x[count_m-K])\nelse:\n # print("san")\n ans = min(tmp, tmp2)\n\n\nprint(ans)\n', 'N, K = map(int, input().split())\nx = list(map(int, input().split()))\n\ncount_m = 0\ncount_p = 0\nfor i in range(N):\n if x[i] > 0:\n count_m = i\n count_p = N-i\n break\n elif x[i] == 0:\n count_m = i\n count_p = N-i-1\n K -= 1\n N -= 1\n x.remove(x[i])\n break\nif count_m == 0 and count_p == 0:\n count_m = N\n\nans = 0\n \n\ny = K\nz = K - y\n\n\nif count_m >= 1 and count_p>=1:\n # for j in (range(1,y)):\n # if count_m-j>=0 and count_m+y-1-j<N:\n # print(x[count_m+y-1-j], x[count_m-j])\n tmp = min(x[count_m+y-1-j]-x[count_m-j] *2 for j in range(1, y) if count_m-j>=0 and count_m+y-1-j<N)\n tmp2 = min(x[count_m+y-1-j]*2-x[count_m-j] for j in range(1, y) if count_m-j>=0 and count_m+y-1-j<N)\nelse:\n tmp = tmp2 = 1000000000\n\nif N==0:\n ans = 0\n\n\nelif count_p>=K:\n # print(y, "1chi")\n ans = min(tmp, tmp2, x[count_m+min(y, count_p)-1])\nelif count_m>=K:\n #print("ni")\n ans = min(tmp, tmp2, -x[count_m-K])\nelse:\n #print("san", tmp, tmp2)\n ans = min(tmp, tmp2)\n\n\nprint(ans)\n'] | ['Runtime Error', 'Runtime Error', 'Runtime Error', 'Runtime Error', 'Runtime Error', 'Accepted'] | ['s443980963', 's550701223', 's890566134', 's931672816', 's962692596', 's489302443'] | [14480.0, 14240.0, 14228.0, 14252.0, 2940.0, 14484.0] | [318.0, 107.0, 302.0, 307.0, 17.0, 107.0] | [1116, 1164, 1078, 1074, 1164, 1072] |
p03274 | u445226180 | 2,000 | 1,048,576 | There are N candles placed on a number line. The i-th candle from the left is placed on coordinate x_i. Here, x_1 < x_2 < ... < x_N holds. Initially, no candles are burning. Snuke decides to light K of the N candles. Now, he is at coordinate 0. He can move left and right along the line with speed 1. He can also light a candle when he is at the same position as the candle, in negligible time. Find the minimum time required to light K candles. | ['N,K=map(int,input().split(" "))\nX=sorted(list(map(int,input().split(" "))))\n\nans=0\nfor i in range(N-K+1):\n tans=abs(X[i]-X[i+K])+abs(X[i])\n\n if i==0 or ans>tans:\n ans=tans\n \nprint(ans)', 'N,K=map(int,input().split(" "))\nX=sorted(list(map(int,input().split(" "))))\n\nans=0\nfor i in range(N-K+1):\n tans=abs(X[0]-X[-1])+abs(X[0])\n\n if i==0 or ans>tans:\n ans=tans\n \nprint(ans)', 'N,K=map(int,input().split(" "))\nX=sorted(list(map(int,input().split(" "))))\n\nans=0\nfor i in range(N-K+1):\n tans=abs(X[i]-X[i+K-1])+abs(X[i])\n\n if i==0 or ans>tans:\n ans=tans\n\nfor i in range(N-K+1):\n tans=abs(X[i]-X[i+K-1])+abs(X[i+K-1])\n\n if ans>tans:\n ans=tans\n\nprint(ans)'] | ['Runtime Error', 'Wrong Answer', 'Accepted'] | ['s107349246', 's168142280', 's672742712'] | [14568.0, 14384.0, 14252.0] | [69.0, 61.0, 99.0] | [200, 199, 299] |
p03274 | u445624660 | 2,000 | 1,048,576 | There are N candles placed on a number line. The i-th candle from the left is placed on coordinate x_i. Here, x_1 < x_2 < ... < x_N holds. Initially, no candles are burning. Snuke decides to light K of the N candles. Now, he is at coordinate 0. He can move left and right along the line with speed 1. He can also light a candle when he is at the same position as the candle, in negligible time. Find the minimum time required to light K candles. | ['\n\n\nn, k = map(int, input().split())\narr = list(map(int, input().split()))\n\n\ndef lower_bound(arr, n):\n \n left, right = 0, len(arr)\n while left < right:\n mid = (left + right) // 2\n if arr[mid] < n:\n left = mid + 1\n else:\n right = mid\n return right\n\n\nidx = lower_bound(arr, 0)\nprint("idx={}".format(idx))\nans = 10 ** 16\n\nfor i in range(n - k + 1):\n if i + k < idx:\n print("under zero")\n ans = min(ans, abs(arr[i]))\n elif arr[i] < 0 and idx <= i + k:\n print("between zero")\n ans = min(\n ans, 2 * abs(arr[i]) + arr[i + k - 1], abs(arr[i]) + 2 * arr[i + k - 1]\n )\n else:\n print("upper zero")\n ans = min(ans, abs(arr[i + k - 1]))\n\nprint(ans)\n', '\n\nn, k = map(int, input().split())\narr = list(map(int, input().split()))\nans = 10 ** 10\nfor i in range(n - k + 1):\n if arr[i] < 0 and arr[i + k - 1] < 0:\n ans = min(ans, abs(arr[i]))\n elif arr[i] < 0 and 0 <= arr[i + k - 1]:\n ans = min(\n ans, abs(arr[i]) * 2 + arr[i + k - 1], abs(arr[i]) + arr[i + k - 1] * 2\n )\n elif 0 <= arr[i] <= arr[i + k - 1]:\n ans = min(ans, arr[i + k - 1])\n\n # print("taken from {}, ans = {}".format(arr[i : i + k], ans))\nprint(ans)\n'] | ['Wrong Answer', 'Accepted'] | ['s213359442', 's570689224'] | [14532.0, 14480.0] | [128.0, 102.0] | [1016, 681] |
p03274 | u445927145 | 2,000 | 1,048,576 | There are N candles placed on a number line. The i-th candle from the left is placed on coordinate x_i. Here, x_1 < x_2 < ... < x_N holds. Initially, no candles are burning. Snuke decides to light K of the N candles. Now, he is at coordinate 0. He can move left and right along the line with speed 1. He can also light a candle when he is at the same position as the candle, in negligible time. Find the minimum time required to light K candles. | ['class Solver(object):\n def __init__(self):\n self.n, self.k = list(map(int, input().split(" ")))\n self.x_s = sorted(list(map(int, input().split(" "))))\n\n def solve(self):\n candidates = []\n for i in range(self.n - self.k + 1): # 0 .. n-k\n candidates.append((i, i + self.k - 1))\n\n best_candidate = None\n best_distance = -1\n for c in candidates:\n d = self.distance(c)\n if (best_distance != -1) and (d < best_distance):\n best_candidate = c\n best_distance = d\n # print(best_candidate)\n print(best_distance)\n\n def distance(self, candidate):\n left = self.x_s[candidate[0]]\n right = self.x_s[candidate[1]]\n # X X X 0\n if right <= 0:\n return abs(left)\n # 0 X X X\n elif left >= 0:\n return abs(right)\n # X 0 X X\n elif abs(left) < abs(right):\n return abs(left) + abs(left) + abs(right)\n # X X 0 X\n else:\n return abs(right) + abs(right) + abs(left)\n\n def filter(self):\n # Only want -k .. k elements\n right = None\n counter = 0\n for i, v in enumerate(self.x_s):\n if v >= 0:\n counter += 1\n if counter == self.k:\n right = i + 1\n break\n if right is None:\n right = len(self.x_s)\n\n left = None\n counter = 0\n for i, v in reversed(list(enumerate(self.x_s))):\n if v <= 0:\n counter += 1\n if counter == self.k:\n left = i\n break\n if left is None:\n left = 0\n return self.x_s[left:right]\n\n\nif __name__ == "__main__":\n s = Solver()\n s.solve()', 'class Solver(object):\n def __init__(self):\n self.n, self.k = list(map(int, input().split(" ")))\n self.x_s = sorted(list(map(int, input().split(" "))))\n \n def solve(self):\n candidates = []\n for i in range(self.n - self.k + 1): # 0 .. n-k\n candidates.append((i, i + self.k - 1))\n # print(self.x_s[i:i+self.k])\n best_candidate = candidates[0]\n best_distance = self.distance(best_candidate)\n for c in candidates[1:]:\n d = self.distance(c)\n if d < best_distance:\n best_candidate = c\n best_distance = d\n # print(best_candidate)\n print(best_distance)\n \n def distance(self, candidate):\n left = self.x_s[candidate[0]]\n right = self.x_s[candidate[1]]\n # X X X 0\n if right <= 0:\n return abs(left)\n # 0 X X X\n elif left >= 0:\n return abs(right)\n # X 0 X X\n elif abs(left) < abs(right):\n return abs(left) + abs(left) + abs(right)\n # X X 0 X\n else:\n return abs(right) + abs(right) + abs(left)\n \n def filter(self):\n # Only want -k .. k elements\n right = None\n counter = 0\n for i, v in enumerate(self.x_s):\n if v >= 0:\n counter += 1\n if counter == self.k:\n right = i + 1\n break\n if right is None:\n right = len(self.x_s)\n \n left = None\n counter = 0\n for i, v in reversed(list(enumerate(self.x_s))):\n if v <= 0:\n counter += 1\n if counter == self.k:\n left = i\n break\n if left is None:\n left = 0\n return self.x_s[left:right]\n \n \nif __name__ == "__main__":\n s = Solver()\n s.solve()'] | ['Wrong Answer', 'Accepted'] | ['s880287372', 's242553746'] | [14384.0, 14368.0] | [86.0, 89.0] | [1821, 1880] |
p03274 | u451017206 | 2,000 | 1,048,576 | There are N candles placed on a number line. The i-th candle from the left is placed on coordinate x_i. Here, x_1 < x_2 < ... < x_N holds. Initially, no candles are burning. Snuke decides to light K of the N candles. Now, he is at coordinate 0. He can move left and right along the line with speed 1. He can also light a candle when he is at the same position as the candle, in negligible time. Find the minimum time required to light K candles. | ["N, K = map(int, input().split())\nx = [int(i) for i in input().split()]\na = []\na2 = []\nfor i in x:\n if i < 0:\n a2.append(2 * abs(i))\n else:\n a.append(i)\n\nif len(a2) == 0:\n print(a[K-1])\n exit()\na2 = sorted(a2)\nc1 = float('inf')\n\nfor i, v in enumerate(a):\n if K - i > len(a2):\n continue\n c1 = min(c1, v + a2[K - i])\n\nb = []\nb2 = []\nfor i in x:\n if i > 0:\n b2.append(2 * abs(i))\n else:\n b.append(-i)\nb = sorted(b)\n\nif len(b2) == 0:\n print(b[K-1])\n exit()\n\nc2 = float('inf')\nfor i, v in enumerate(b):\n if K - i > len(b2):\n continue\n c2 = min(c2, v + b2[K - i])\n\nprint(min(c1,c2))", "N, K = map(int, input().split())\nx = [int(i) for i in input().split()]\na = []\na2 = []\nfor i in x:\n if i < 0:\n a2.append(2 * abs(i))\n else:\n a.append(i)\n\nif len(a2) == 0:\n print(a[K-1])\n exit()\na2 = sorted(a2)\nc1 = float('inf')\n\nfor i, v in enumerate(a):\n if K - i >= len(a2):\n continue\n c1 = min(c1, v + a2[K - i])\n\nb = []\nb2 = []\nfor i in x:\n if i > 0:\n b2.append(2 * abs(i))\n else:\n b.append(-i)\nb = sorted(b)\n\nif len(b2) == 0:\n print(b[K-1])\n exit()\n\nc2 = float('inf')\nfor i, v in enumerate(b):\n if K - i >= len(b2):\n continue\n c2 = min(c2, v + b2[K - i])\n\nprint(min(c1,c2))", "N, K = map(int, input().split())\nx = [int(i) for i in input().split()]\na = []\na2 = []\nfor i in x:\n if i < 0:\n a2.append(2 * abs(i))\n else:\n a.append(i)\n\nif len(a2) == 0:\n print(a[K-1])\n exit()\na2 = sorted(a2)\nc1 = float('inf')\n\nfor i, v in enumerate(a):\n if K - i >= len(a2):\n break\n c1 = min(c1, v + a2[K - i])\n\nb = []\nb2 = []\nfor i in x:\n if i > 0:\n b2.append(2 * abs(i))\n else:\n b.append(-i)\nb = sorted(b)\n\nif len(b2) == 0:\n print(b[K-1])\n exit()\n\nc2 = float('inf')\nfor i, v in enumerate(b):\n if K - i >= len(b2):\n break\n c2 = min(c2, v + b2[K - i])\n\nprint(min(c1,c2))", "N, K = map(int, input().split())\nx = [int(i) for i in input().split()]\nans = float('inf')\nfor i in range(N-K+1):\n l = x[i]\n r = x[i+K-1]\n a = abs(l) + abs(r - l)\n b = abs(r) + abs(r - l)\n ans = min(a,b,ans)\nprint(ans)"] | ['Runtime Error', 'Wrong Answer', 'Wrong Answer', 'Accepted'] | ['s012964468', 's259878382', 's729772971', 's943912311'] | [15788.0, 15632.0, 15788.0, 14392.0] | [103.0, 140.0, 113.0, 97.0] | [653, 655, 649, 232] |
p03274 | u455317716 | 2,000 | 1,048,576 | There are N candles placed on a number line. The i-th candle from the left is placed on coordinate x_i. Here, x_1 < x_2 < ... < x_N holds. Initially, no candles are burning. Snuke decides to light K of the N candles. Now, he is at coordinate 0. He can move left and right along the line with speed 1. He can also light a candle when he is at the same position as the candle, in negligible time. Find the minimum time required to light K candles. | ['N,K = map(int,input().split())\nx = list(map(int,input().split()))\nif K==1 and (0 in x):\n print(0)\nelse:\n if 0 in x:\n pass\n else:\n K += 1\n counter = 0\n for i in x:\n if i > 0:\n break\n else:\n counter += 1\n x.insert(counter,0)\n\n result = []\n g,s = x.index(0),x.index(0)-K+1\n while (not s>x.index(0)):\n if s<0 or g>(len(x)-1):\n s += 1\n g += 1\n continue\n else:\n result.append(2*(-x[s]) + x[g])\n result.append(-x[s] + 2*(x[g]))\n s += 1\n g += 1\n print(result.sort()[0])', 'N,K = map(int,input().split())\nx = list(map(int,input().split()))\n\nresult = []\nfor i in range(N-K+1):\n s,g = i,i+K-1\n result.append(abs(x[s]) + abs(x[s] - x[g]))\n result.append(abs(x[g]) + abs(x[g] - x[s]))\nresult.sort()\nprint(result[0])'] | ['Runtime Error', 'Accepted'] | ['s158712099', 's350040086'] | [14844.0, 14252.0] | [2104.0, 103.0] | [660, 246] |
p03274 | u497625442 | 2,000 | 1,048,576 | There are N candles placed on a number line. The i-th candle from the left is placed on coordinate x_i. Here, x_1 < x_2 < ... < x_N holds. Initially, no candles are burning. Snuke decides to light K of the N candles. Now, he is at coordinate 0. He can move left and right along the line with speed 1. He can also light a candle when he is at the same position as the candle, in negligible time. Find the minimum time required to light K candles. | ['N, K = map(int,input().split())\nx = list(map(int,input().split()))\n\no = 0\nif x[N-1] <= 0:\n\tprint(x[N-K])\n\texit()\nif x[0] >= 0:\n\tprint(x[K-1])\n\texit()\nif 0 in x:\n\ti = x.index(0)\n\tdel x[i]\n\tN,K = N-1,K=1\n\nwhile x[o] < 0:\n\to += 1\n\tif o == N-1:\n\t\tbreak\n\nMIN = float("inf")\nfor i in range(-K-1,K+1,1):\n\tl = o - i+1\n\tr = o + K-i\n\tif not(l < 0 or l >= N or r < 0 or r >= N):\n\t\tcur1 = 2* abs(x[l]) + abs(x[r])\n#\t\tprint([l,r,cur1,cur2])\n\t\tif cur1 < MIN:\n\t\t\tMIN = cur1\n\t\tif cur2 < MIN:\n\t\t\tMIN = cur2\nprint(MIN)\n\n\n\n', 'N, K = map(int,input().split())\nx = list(map(int,input().split()))\n\nMIN = float("inf")\nfor i in range(N-K+1):\n\tl = i\n\tr = i + K - 1\n\t\tcur1 = 2*abs(x[l]) + abs(x[r]-x[l])\n\t\tcur2 = abs(x[l]) + 2*abs(x[r]-x[l])\n#\t\tprint([l,r,cur1,cur2])\n\t\tif cur1 < MIN:\n\t\t\tMIN = cur1\n\t\tif cur2 < MIN:\n\t\t\tMIN = cur2\nprint(MIN)\n\n\n\n', '#N, K = map(int,input().split())\n#x = list(map(int,input().split()))\n\no = 0\nif x[N-1] < 0:\n\tprint(x[N-K])\n\texit()\nif x[0] > 0:\n\tprint(x[K-1])\n\texit()\n\nwhile x[o] < 0:\n\to += 1\n\tif o == N-1:\n\t\tbreak\n\nMIN = float("inf")\nfor i in range(-K-1,K+1,1):\n\tl = o - i+1\n\tr = o + K-i\n\tif not(l < 0 or l >= N or r < 0 or r >= N):\n\t\tcur1 = 2* abs(x[l]) + abs(x[r])\n\t\tcur2 = abs(x[l]) + 2*abs(x[r])\n#\t\tprint([l,r,cur1,cur2])\n\t\tif cur1 < MIN:\n\t\t\tMIN = cur1\n\t\tif cur2 < MIN:\n\t\t\tMIN = cur2\nprint(MIN)\n\n\n\n', 'N, K = map(int,input().split())\nx = list(map(int,input().split()))\n\no = 0\nif x[N-1] <= 0:\n\tprint(x[N-K])\n\texit()\nif x[0] >= 0:\n\tprint(x[K-1])\n\texit()\n\nMIN = float("inf")\nfor i in range(N-K+1):\n\tl = i\n\tr = i + K\n\t\tcur1 = 2*abs(x[l]) + abs(x[r]-x[l])\n\t\tcur2 = abs(x[l]) + 2*abs(x[r]-x[l])\n#\t\tprint([l,r,cur1,cur2])\n\t\tif cur1 < MIN:\n\t\t\tMIN = cur1\n\t\tif cur2 < MIN:\n\t\t\tMIN = cur2\nprint(MIN)\n\n\n\n', '#N, K = map(int,input().split())\n#x = list(map(int,input().split()))\n#N, K = 5, 3\nN,K = 8, 5\nx = list(map(int,"-9 -7 -4 -3 1 2 3 4".split()))\ninf = float("inf")\norigin = 0\nif x[N-1] < 0:\n\tprint(x[N-K])\n\texit()\nif x[0] > 0:\n\tprint(x[K-1])\n\texit()\n\nwhile x[origin] < 0:\n\torigin += 1\n\tif origin == N-1:\n\t\tbreak\n\nMIN = float("inf")\nfor i in range(-K,K+1,1):\n\tl = origin - i+1\n\tr = origin + K-i\n\tif not(l < 0 or l >= N or r < 0 or r >= N):\n\t\tcur1 = 2* abs(x[l]) + abs(x[r])\n\t\tcur2 = abs(x[l]) + 2*abs(x[r])\n#\t\tprint([l,r,cur1,cur2])\n\t\tif cur1 < MIN:\n\t\t\tMIN = cur1\n\t\tif cur2 < MIN:\n\t\t\tMIN = cur2\nprint(MIN)\n\n\n\n', 'N, K = map(int,input().split())\nx = list(map(int,input().split()))\n\nMIN = float("inf")\nfor i in range(N-K+1):\n\tl = i\n\tr = i + K - 1\n\tcur1 = abs(x[l]) + abs(x[r]-x[l])\n\tcur2 = abs(x[r]) + abs(x[r]-x[l])\n#\tprint([l,r,cur1,cur2])\n\tif cur1 < MIN:\n\t\tMIN = cur1\n\tif cur2 < MIN:\n\t\tMIN = cur2\nprint(MIN)\n'] | ['Runtime Error', 'Runtime Error', 'Runtime Error', 'Runtime Error', 'Wrong Answer', 'Accepted'] | ['s266142328', 's530808733', 's725543172', 's847759556', 's870423601', 's202670977'] | [3064.0, 2940.0, 3064.0, 2940.0, 3064.0, 14384.0] | [18.0, 17.0, 18.0, 17.0, 17.0, 87.0] | [504, 310, 485, 389, 604, 296] |
p03274 | u503221936 | 2,000 | 1,048,576 | There are N candles placed on a number line. The i-th candle from the left is placed on coordinate x_i. Here, x_1 < x_2 < ... < x_N holds. Initially, no candles are burning. Snuke decides to light K of the N candles. Now, he is at coordinate 0. He can move left and right along the line with speed 1. He can also light a candle when he is at the same position as the candle, in negligible time. Find the minimum time required to light K candles. | ["import sys\n\ndef main(lines):\n N, K = map(int, lines[0].split())\n a = list(map(int, lines[1].split()))\n ans = 1000000000000\n for i in range(N):\n if i + K - 1 >= N:\n break\n b = a[i]\n c = a[i + K - 1]\n if b < 0 and c >= 0:\n ans = min(ans, max(abs(b), abs(c)) + 2*min(abs(b), abs(c)))\n else:\n ans = min(ans, min(abs(b), abs(c)))\n print(ans)\n\n\nif __name__ == '__main__':\n lines = []\n for l in sys.stdin:\n lines.append(l.rstrip('\\r\\n'))\n main(lines)", "import sys\n\ndef main(lines):\n N, K = map(int, lines[0].split())\n a = list(map(int, lines[1].split()))\n ans = 1000000000000\n for i in range(N):\n if i + K - 1 >= N:\n break\n b = a[i]\n c = a[i + K - 1]\n if b < 0 and c >= 0:\n ans = min(ans, max(abs(b), abs(c)) + 2*min(abs(b), abs(c)))\n else:\n ans = min(ans, man(abs(b), abs(c)))\n print(ans)\n\n\nif __name__ == '__main__':\n lines = []\n for l in sys.stdin:\n lines.append(l.rstrip('\\r\\n'))\n main(lines)", "import sys\n\ndef main(lines):\n N, K = map(int, lines[0].split())\n a = list(map(int, lines[1].split()))\n ans = 1000000000000\n for i in range(N):\n if i + K - 1 >= N:\n break\n b = a[i]\n c = a[i + K - 1]\n if b < 0 and c >= 0:\n ans = min(ans, max(abs(b), abs(c)) + 2*min(abs(b), abs(c)))\n else:\n ans = min(ans, max(abs(b), abs(c)))\n print(ans)\n\n\nif __name__ == '__main__':\n lines = []\n for l in sys.stdin:\n lines.append(l.rstrip('\\r\\n'))\n main(lines)"] | ['Wrong Answer', 'Runtime Error', 'Accepted'] | ['s618689545', 's979458592', 's481964643'] | [16164.0, 16164.0, 16164.0] | [86.0, 89.0, 87.0] | [494, 494, 494] |
p03274 | u504562455 | 2,000 | 1,048,576 | There are N candles placed on a number line. The i-th candle from the left is placed on coordinate x_i. Here, x_1 < x_2 < ... < x_N holds. Initially, no candles are burning. Snuke decides to light K of the N candles. Now, he is at coordinate 0. He can move left and right along the line with speed 1. He can also light a candle when he is at the same position as the candle, in negligible time. Find the minimum time required to light K candles. | ['N, K = [int(_) for _ in input().split()]\nx = [int(_) for _ in input().split()]\npos_i = -1\nfor i in range(len(x)):\n if x[i] >= 0:\n pos_i = i\n break\n\nmin_t = 200000000\nif pos_i == -1:\n min_t = -x[-K]\nelse:\n for i in range(N-K+1):\n if i+K < pos_i:\n min_t = -x[pos_i-K]\n elif pos_i <= i:\n min_t = x[pos_i+K-1]\n else:\n min_t = min(min_t, x[K+i-1]-2*x[i], x[K+i-1]*2-x[i])\n\nprint(min_t)', 'N, K = [int(_) for _ in input().split()]\nx = [int(_) for _ in input().split()]\npos_i = -1\nfor i in range(len(x)):\n if x[i] > 0:\n pos_i = i\n break\n\nmin_t = 300000000\nif pos_i == -1:\n min_t = -x[-K]\nelse:\n for i in range(N-K+1):\n if i+K-1 < pos_i:\n min_t = min(min_t, -x[pos_i-K])\n elif pos_i <= i:\n min_t = min(min_t, x[pos_i+K-1])\n else:\n min_t = min(min_t, x[K+i-1]-x[i]*2, x[K+i-1]*2-x[i])\n\nprint(min_t)'] | ['Wrong Answer', 'Accepted'] | ['s803098210', 's761938782'] | [14224.0, 14480.0] | [98.0, 93.0] | [457, 482] |
p03274 | u506858457 | 2,000 | 1,048,576 | There are N candles placed on a number line. The i-th candle from the left is placed on coordinate x_i. Here, x_1 < x_2 < ... < x_N holds. Initially, no candles are burning. Snuke decides to light K of the N candles. Now, he is at coordinate 0. He can move left and right along the line with speed 1. He can also light a candle when he is at the same position as the candle, in negligible time. Find the minimum time required to light K candles. | ['N,K=map(int,input().split())\nx=sorted(list(map(int,input().split())))\n\nans=0\nfor i in range(N-K+1):\n tmp1=abs(x[i])+abs(x[i+K-1]-x[i])\n tmp2=abs(x[i+K-1])+abs(x[i+K-1]-x[i])\n tmp=min(tmp1,tmp2)\n ans=min(tmp,ans)\n\nprint(ans)\n\n ', 'N,K=map(int,input().split())\nx=sorted(list(map(int,input().split())))\n\nans=1000000000\nfor i in range(N-K+1):\n tmp1=abs(x[i])+abs(x[i+K-1]-x[i])\n tmp2=abs(x[i+K-1])+abs(x[i+K-1]-x[i])\n tmp=min(tmp1,tmp2)\n ans=min(tmp,ans)\n\nprint(ans)\n\n '] | ['Wrong Answer', 'Accepted'] | ['s960476520', 's715274078'] | [14568.0, 14252.0] | [107.0, 106.0] | [240, 249] |
p03274 | u518042385 | 2,000 | 1,048,576 | There are N candles placed on a number line. The i-th candle from the left is placed on coordinate x_i. Here, x_1 < x_2 < ... < x_N holds. Initially, no candles are burning. Snuke decides to light K of the N candles. Now, he is at coordinate 0. He can move left and right along the line with speed 1. He can also light a candle when he is at the same position as the candle, in negligible time. Find the minimum time required to light K candles. | ['n,m=map(int,input().split())\nl=list(map(int,input().split()))\nl1=[]\nfor i in range(n-m+1):\n if l[i]>=0:\n l1.append(l[i+m]-l[i])\n elif l[i]<=0<=l[i+m]:\n l1.append(l[i+m]-l[i]+min(l[i],l[i+m]))\n else:\n l1.append(l[i+m]-l[i])\nprint(min(l1)) ', 'n,m=map(int,input().split())\nl=list(map(int,input().split()))\nl1=[]\nfor i in range(n-m+1):\n if l[i]>=0:\n l1.append(l[i+m-1])\n elif l[i]<=0<=l[i+m-1]:\n l1.append(l[i+m-1]-l[i]+min(abs(l[i]),abs(l[i+m-1])))\n else:\n l1.append(abs(l[i]))\nprint(min(l1)) \n'] | ['Runtime Error', 'Accepted'] | ['s698468707', 's667075406'] | [14252.0, 14384.0] | [83.0, 95.0] | [253, 262] |
p03274 | u518556834 | 2,000 | 1,048,576 | There are N candles placed on a number line. The i-th candle from the left is placed on coordinate x_i. Here, x_1 < x_2 < ... < x_N holds. Initially, no candles are burning. Snuke decides to light K of the N candles. Now, he is at coordinate 0. He can move left and right along the line with speed 1. He can also light a candle when he is at the same position as the candle, in negligible time. Find the minimum time required to light K candles. | ['N,K = map(int,input().split())\na = list(map(int,input().split()))\nb = []\nfor i in range(N-K+1):\n b.append(min(abs(a[i])+abs(a[i+k-1]-a[i]),abs(a[i+k-1])+abs(a[i+k-1]-a[i])))\nprint(min(b))\n ', 'N,K = map(int,input().split())\na = list(map(int,input().split()))\nb = []\ndis = N-K+1\nfor i in range(dis):\n b.append(min(abs(a[i])+abs(a[i]-a[i+K-1]),abs(a[i+K-1])+abs(a[i+K-1]-a[i])))\nprint(min(b))\n \n'] | ['Runtime Error', 'Accepted'] | ['s741122641', 's435236217'] | [14380.0, 14384.0] | [43.0, 100.0] | [191, 204] |
p03274 | u519968172 | 2,000 | 1,048,576 | There are N candles placed on a number line. The i-th candle from the left is placed on coordinate x_i. Here, x_1 < x_2 < ... < x_N holds. Initially, no candles are burning. Snuke decides to light K of the N candles. Now, he is at coordinate 0. He can move left and right along the line with speed 1. He can also light a candle when he is at the same position as the candle, in negligible time. Find the minimum time required to light K candles. | ['n,k=map(int,input().split())\nx=list(map(int,input().split()))\n\nst=0\nm=3*10**8\nfor i in range(n-1):\n if x[i]<0 and x[i+1]>=0:\n st=i+1\n\nfor i in range(n-k+2):\n mi=x[k+i-1]-x[i]+min(abs(x[k+i-1]),abs(x[i]))\n print(x[k+i-1],x[i],mi)\n if k+i<st or i>st:continue\n if mi <m:m=mi\nprint(m)', 'n,k=map(int,input().split())\nx=list(map(int,input().split()))\n\nst=0\nm=3*10**8\nfor i in range(n-1):\n if x[i]<0 and x[i+1]>=0:\n st=i+1\n\nfor i in range(n-k+1):\n mi=x[k+i-1]-x[i]+min(abs(x[k+i-1]),abs(x[i]))\n print(x[k+i-1],x[i],mi)\n if k+i<st or i>st:continue\n if mi <m:m=mi\nprint(m)', 'n,k=map(int,input().split())\nx=list(map(int,input().split()))\n\nmt=5*10**8\n\nfor i in range(n-k+1):\n mt=min(mt,2*abs(x[i])+abs(x[i+k-1]),abs(x[i])+2*abs(x[i+k-1]))\n\nif x[0]>0:mt=min(mt,x[k-1])\nelif x[-1]<0:mt=min(mt,abs(x[-1-k+1]))\nprint(mt)\n \n '] | ['Runtime Error', 'Wrong Answer', 'Accepted'] | ['s708626240', 's856171586', 's507984248'] | [20120.0, 20056.0, 20084.0] | [136.0, 140.0, 90.0] | [288, 288, 248] |
p03274 | u527261492 | 2,000 | 1,048,576 | There are N candles placed on a number line. The i-th candle from the left is placed on coordinate x_i. Here, x_1 < x_2 < ... < x_N holds. Initially, no candles are burning. Snuke decides to light K of the N candles. Now, he is at coordinate 0. He can move left and right along the line with speed 1. He can also light a candle when he is at the same position as the candle, in negligible time. Find the minimum time required to light K candles. | ['n,k=map(int,input().split())\nx=list(map(int,input().split()))\ntime=1000000\nfor i in range(n-k+1):\n l=x[i]\n r=x[i+k-1]\n time=min(time,abs(l)+l-r,abs(r)+l-r)\nprint(time)\n \n \n \n', "n,k=map(int,input().split())\nx=list(map(int,input().split()))\ntime=float'inf'\nfor i in range(n-k+1):\n l=x[i]\n r=x[i+k-1]\n time=min(time,abs(l)+r-l,abs(r)+r-l)\nprint(time)\n \n \n \n", 'n,k=map(int,input().split())\nx=list(map(int,input().split()))\ntime=100000000000\nfor i in range(n-k+1):\n l=x[i]\n r=x[i+k-1]\n time=min(time,abs(l)+r-l,abs(r)+r-l)\nprint(time)\n \n \n \n'] | ['Wrong Answer', 'Runtime Error', 'Accepted'] | ['s574608002', 's930464931', 's360311718'] | [14384.0, 2940.0, 14252.0] | [82.0, 17.0, 81.0] | [184, 187, 189] |
p03274 | u559126797 | 2,000 | 1,048,576 | There are N candles placed on a number line. The i-th candle from the left is placed on coordinate x_i. Here, x_1 < x_2 < ... < x_N holds. Initially, no candles are burning. Snuke decides to light K of the N candles. Now, he is at coordinate 0. He can move left and right along the line with speed 1. He can also light a candle when he is at the same position as the candle, in negligible time. Find the minimum time required to light K candles. | ['N,K=map(int,input().split())\na=list(map(int,input().split()))\nb=[]\nfor i in (N-K+1):\n if a[i]<0:\n b.append(-2*a[i]+a[i+K-1])\n else:\n b.append(a[i]+a[i+K-1])\nprint(min(b))\n', 'N,K=map(int,input().split())\na=list(map(int,input().split()))\nb=[]\nfor i in range(N-K+1):\n b.append(min(abs(a[i])+abs(a[i+K-1]-a[i]),abs(a[i+K-1])+abs(a[i]-a[i+K-1]))\nprint(min(b))\n', 'N,K=map(int,input().split())\na=list(map(int,input().split()))\nb=[]\nfor i in range(N-K+1):\n b.append(min(abs(a[i])+abs(a[i+K-1]-a[i]),abs(a[i+K-1])+abs(a[i]-a[i+K-1])))\nprint(min(b))\n'] | ['Runtime Error', 'Runtime Error', 'Accepted'] | ['s635211046', 's746260384', 's072224785'] | [14384.0, 2940.0, 14252.0] | [42.0, 17.0, 99.0] | [191, 184, 185] |
p03274 | u560867850 | 2,000 | 1,048,576 | There are N candles placed on a number line. The i-th candle from the left is placed on coordinate x_i. Here, x_1 < x_2 < ... < x_N holds. Initially, no candles are burning. Snuke decides to light K of the N candles. Now, he is at coordinate 0. He can move left and right along the line with speed 1. He can also light a candle when he is at the same position as the candle, in negligible time. Find the minimum time required to light K candles. | ['import sys\ninput = sys.stdin.readline\n\n\ndef main():\n N, K = map(int, input().split())\n X = [int(c) for c in input().split()]\n\n def fullsearch():\n for i in range(N-K):\n l = X[i]\n r = X[i+K-1]\n distance = abs(r - l)\n if abs(l) > abs(r):\n distance += r\n else:\n distance += l\n yield distance\n\n a = list(fullsearch())\n if not a:\n print(0)\n else:\n print(min(a))\n\n\nmain()', 'import sys\ninput = sys.stdin.readline\n\nX = []\nK = 0\ndef fullsearch():\n for l, r in zip(X, X[K-1:]):\n distance = abs(r - l)\n yield distance + abs(r)\n yield distance + abs(l)\n\ndef main():\n global X, K\n _, K = map(int, input().split())\n X = list(map(int, input().split()))\n\n print(min(fullsearch()))\n\nmain()'] | ['Wrong Answer', 'Accepted'] | ['s503639115', 's207366892'] | [14172.0, 14172.0] | [66.0, 58.0] | [499, 340] |
p03274 | u566428756 | 2,000 | 1,048,576 | There are N candles placed on a number line. The i-th candle from the left is placed on coordinate x_i. Here, x_1 < x_2 < ... < x_N holds. Initially, no candles are burning. Snuke decides to light K of the N candles. Now, he is at coordinate 0. He can move left and right along the line with speed 1. He can also light a candle when he is at the same position as the candle, in negligible time. Find the minimum time required to light K candles. | ["N,K=map(int,input().split())\nX=list(map(int,input().split()))\nans=float('inf')\nfor i in range(N-K+1):\n \tl=i\n r=l+K-1\n ans=min(ans,min(abs(X[l]),abs(X[r]))+X[r]-X[l])\nprint(ans)", "N,K=map(int,input().split())\nX=list(map(int,input().split()))\nans=float('inf')\nfor l in range(N-K+1):\n r=l+K-1\n ans=min(ans,min(abs(X[l]),abs(X[r]))+X[r]-X[l])\nprint(ans)"] | ['Runtime Error', 'Accepted'] | ['s894526815', 's748068544'] | [2940.0, 14384.0] | [17.0, 86.0] | [183, 176] |
p03274 | u573272932 | 2,000 | 1,048,576 | There are N candles placed on a number line. The i-th candle from the left is placed on coordinate x_i. Here, x_1 < x_2 < ... < x_N holds. Initially, no candles are burning. Snuke decides to light K of the N candles. Now, he is at coordinate 0. He can move left and right along the line with speed 1. He can also light a candle when he is at the same position as the candle, in negligible time. Find the minimum time required to light K candles. | ['N, K = map(int, input().split())\nX = list(map(int, input().split()))\nk = 2*N\nfor i in range(N-K+1):\n\tl = X[i]\n\tr = X[i+K-1]\n\tk = min(k, abs(l)+abs(r-l), abs(r)+abs(r-l))\nprint(k)', 'N, K = map(int, input().split())\nX = list(map(int, input().split()))\nk = float("INF")\nfor i in range(N-K+1):\n\tl = X[i]\n\tr = X[i+K-1]\n\tk = min(k, abs(l)+abs(r-l), abs(r)+abs(r-l))\nprint(k)'] | ['Wrong Answer', 'Accepted'] | ['s676389596', 's770530402'] | [14384.0, 14640.0] | [84.0, 94.0] | [178, 187] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.