import sys
def readstr(): return sys.stdin.readline().strip()
def readfloats(): return list(map(float, readstr().split()))
while(True):
N, W = readfloats()
N = int(N)
if (N == 0 and W == 0.0000):
break
max_h = 0
sum_width = 0
total = 0
for i in range(N):
h, w = readfloats()
if sum_width + w > W:
total += max_h
sum_width = w
max_h = h
else:
if(h > max_h):
max_h = h
sum_width+=w
total += max_h
print (f"{total:.4f}")
``` i believe my code is good as it pass the test on the file but it marks wrong answer, is something wrong in my logic ? thanks for reading here the link to the online judge problem : https://onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&category=0&problem=1180&mosmsg=Submission+received+with+ID+29872353
Online Judge