Блог пользователя Hot_Potato

Автор Hot_Potato, история, 5 лет назад, По-английски

https://codeforces.net/problemset/problem/1339/B Hello, i am getting runtime error on this...Can anyone help me out..when i test samples on my own laptop, it is working out fine!!

T = int(input())

for s in range(1,T+1):

N = int(input())

l = [int(input()) for i in range(N)]

l.sort()

p = []

x = len(l)

while (len(l)>2):

    p = [l[0],l[-1]] + p

    l = l[1:-1]

p = l + p


print(*p,sep=" ")
  • Проголосовать: нравится
  • +11
  • Проголосовать: не нравится

»
5 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

This is failing because l = [int(input()) for i in range(N)] is not a valid way to take a line of input in python (the input() function returns the entire line, which cannot be turned into an int).

The correct way to do this is the code l = list(map(int,input().split())).