[Python] WSL Input limit issue

Discussão em 'Python' iniciado por Stack, Fevereiro 12, 2025.

  1. Stack

    Stack Membro Participativo

    I encounter a problem with a python code in WSL when input a large amount of numbers. Here is the code:

    import sys
    max_sum = 0
    # num = int(input())
    # array = input().split()
    def input():
    [n] = [int(x) for x in sys.stdin.readline().split()]
    a = [int(x) for x in sys.stdin.readline().split()]
    return n,a
    def maxSubarray(array, max_sum, num):
    print('num = ',num,'len array = ',len(array))
    for k in range(0,num):
    print('a[',k,'] = ',array[k])
    for i in range(0, num):
    sum = 0
    for j in range(i, num):
    sum += int(array[j])
    if sum > max_sum:
    max_sum = sum
    return max_sum
    num,array =input()
    print(maxSubarray(array, max_sum, num))


    I was tried to run the code with 1000 num and by some reason on the WSL(Ubuntu 24.04.1 LTS) it only store up to 950 num to the array


    a[ 947 ] = -177 a[ 948 ] = 8 a[ 949 ] = -32 Traceback (most recent call last): File "---.py", line 27, in print(maxSubarray(array, max_sum, num)) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "---.py", line 12, in maxSubarray print('a[',k,'] = ',array[k]) ~~~~~^^^ IndexError: list index out of range
    ​

    Fyi: I'm studying DSA and my code run fine in submition site and online complier so i think problem is with the WSL. Thanks for helping

    I try to run it in Native Windows python env 3.12.9 and it can run exactly and store up to 1000 number even with the normal input method


    .... a[ 991 ] = 497 a[ 992 ] = 93 a[ 993 ] = 232 a[ 994 ] = 490 a[ 995 ] = -137 a[ 996 ] = 147 a[ 997 ] = 63 a[ 998 ] = -88 a[ 999 ] = -403 12048
    ​

    Continue reading...

Compartilhe esta Página