https://www.codechef.com/ZCOPRAC/submit/ZCO13003

https://www.codechef.com/ZCOPRAC/submit/ZCO13003

Hi all,
Iam learning python, Some of my codes couldn’t, pass the second subtasks. I dont know why its happening, what should i learn? where i make mistakes?

Here’s my code for Chewing Gum problem which clears Subtask 1 but not 2nd!
Thanks in Advance…

N,K=map(int,input().split())
Hardness= list(map(int,input().split())) [:N]
count=0
for i in Hardness:
if i>=K:
Hardness.remove(i)
N=len(Hardness)
for i in range(0,N-1):
k=i+1
for j in range(k,N):
if(Hardness[i]+Hardness[j])<K:
count=count+1
print(count)

#try this:
n,k=map(int,input().split())
arr=list(map(int,input().split()))
arr=sorted(arr)
ans=0
i=0
j=n-1
while i<n and j!=i: 
  if arr[j]+arr[i]<k:
	  ans+=(j-i)
	  i+=1
  else:
	  j-=1
print(ans)
1 Like