1 / 4
May 2013

m getting a runtime error "NZEC #0" on my submission of problem 1716 http://www.spoj.com/problems/GSS3/1

here's my code

n=int(raw_input())
a=[]
str = raw_input()
a=str.split(' ')
i=0
while i<n:
    a[i]=int(a[i])
    i+=1
m=int(raw_input())
while m>0:
    choice,x,y =raw_input().split(' ')
    choice=int(choice)
    x=int(x)
    y=int(y)
    if choice == 0:     #modify a[x]-> y
    a[x-1] = y
else:               #print max{ai + ai+1 + ... + aj}
    c = a[x-1:y]
    sum = 0
    for i in c:
        sum += i
    c = sorted(c)
    max = c[len(c)-1]
    if sum > max:
        print sum
    else:
        print max

m -= 1

[color=#BF0000]plss help !!![/color]

  • created

    May '13
  • last reply

    Oct '15
  • 3

    replies

  • 936

    views

  • 3

    users

  • 2

    links

Does your code work on IDEONE, and with larger input sets?

NZEC often occurs due to int() conversion on strings which ar not valid integers. You can improve your code by ignoring whitespace in split-function: split() is better than split(' ').

And NZEC could be resulting from index errors...

Anyway, your algorithm will probably not get AC in the end - there's no successfull python submission for this problem. Furthermore, the comments lead towards a segment tree algorithm, which most probably will be quite more efficient than your "naive" approach.

thanx daft for the split() thing.. smile
yes i have checked my code on ideone at boundary conditions
http://ideone.com/oqIlAo2 with n = 10000

its working correctly..

solved this problem using c++(segment tree approach) and got AC too.. smile
but still cant figure out the problem in this approach

any further help will surely be appreciated smile

2 years later

The problem most likely is that the test case in that problem is messed up. You'll see extra whitepaces, bad newlines characters and the like. cin in c++ handles that very well, but for python you'll need to do manually (getting the line and then manually skipping whitespaces until you find a number and then parse the number with int().
e.g. (assuming the newlines are correct, which I think it is not the case)
numbers = [int(s) for s in raw_input().split(" ") if s.isdigit()] #s may be a number or may be