DIVPAIR: Getting python NZEC Error

nzec
practice
python

#1

I am working on the problem “Paying Up”. Despite some time spent trying to solve this issue myself I have yet to find the source of this NZEC error.

http://www.codechef.com/problems/MARCHA1

Here is the code:
It yields the correct answers when I run it. The break statements just make it run a little faster,
the code outputs the correct solution without them as well. Hopefully someone will be able to help me out.

Thanks in advance!

import itertools

cases = int(raw_input())
for i in range(cases):
    found = False
    inputList = []
    notes,request = map(int,raw_input().split())
    for j in range(notes):
        inputList.append(int(raw_input()))
    for k in range(1,len(inputList)+1):
        subsets = list(itertools.combinations(inputList,k))
        for subset in subsets:
            sumOfSet = sum(subset)
            if(sumOfSet == request):
                found = True
                break
        if(found == True):
            break
    if(found == False):
        print "No"
    else:
        print "Yes"

#2

I was able to figure this out the cause of the error was likely because of the fact that I was trying to make use of the combinations function in the itertools module which didn’t exist in python 2.5 (what code chef runs). I was able to get past this by just adjusting my code a little bit and re-submitting in python 3.1.2

This works!
http://www.codechef.com/viewsolution/1023655


#3

actually, the itertools module exists, in Python 2.5.4, but not fully featured as it can be nowadays.

please check this out ! :slight_smile: http://docs.python.org/release/2.5.4/lib/itertools-functions.html


#4

You are correct. I have adjusted my original post to reflect this.


#5

glad to help you.