My issue
Status:
Partially Correct Answer
My code
def max_weight_oranges(n, k, oranges):
dp = [0] * (k + 1) # Initialize a DP table with zeros
for i in range(n):
cost, weight = oranges[i]
for j in range(k, cost - 1, -1):
dp[j] = max(dp[j], dp[j - cost] + weight)
return dp[k]
# Read the number of test cases
t = int(input())
for _ in range(t):
# Read the number of oranges and budget
n, k = map(int, input().split())
# Read the cost and weight of each orange
oranges = []
for _ in range(n):
cost, weight = map(int, input().split())
oranges.append((cost, weight))
# Calculate and print the maximal weight
result = max_weight_oranges(n, k, oranges)
print(result)
Learning course: Kalasalingam Academy of Research and Education
Problem Link: CodeChef: Practical coding for everyone