AritroSinha
AritroSinha

Reputation: 188

Correct sample output but not getting accepted on codechef

I am trying to solve this beginner problem using Python language: https://www.codechef.com/problems/ZUBTRCNT

I have written the code that gives the correct output on sample case. It gives the same output as other accepted answers. But my code is not getting accepted.

For reference: (My code that is not accepted): https://www.codechef.com/viewsolution/40506063

case=int(input())
for c in range(case):
    l,k=map(int,input().split())
    n = l - k + 1
    sum = n * (n + 1) // 2
    print("Case {}:".format(c+1),sum)

(Another persons successful answer): https://www.codechef.com/viewsolution/39844942

t=int(input())
for i in range(0,t):
   l,k=map(int,input().split())
   if(l<k):
      print("Case "+str(i+1)+":","0")
   else:
      m=l-k+1
      m=m*(m+1)//2
      print("Case "+str(i+1)+":",m)

Upvotes: 0

Views: 61

Answers (1)

Deepak Tatyaji Ahire
Deepak Tatyaji Ahire

Reputation: 5311

This is because you missed an important test case where l<k.

Have a look at the following code, which has an Accepted verdict on Codechef:

case=int(input())
for c in range(case):
    l,k=map(int,input().split())
    if(l<k):
      print("Case {}:".format(c+1),0)
    else:
        n = l - k + 1
        sum = n * (n + 1) // 2
        print("Case {}:".format(c+1),sum)

Verdict:

enter image description here

Upvotes: 2

Related Questions