My issue
Wrong Answer: Failed on a hidden test case
My code
import heapq
def min_time_to_collect_chestnuts(t, test_cases):
results = []
for case in test_cases:
m, n, k = case['params']
T = case['T']
P = case['P']
# Priority queue to simulate chestnut drops
pq = []
for i in range(m):
time = T[i]
interval = P[i]
count = 0
while count < k + 1: # Collect up to k + 1 drops
heapq.heappush(pq, time)
time += interval
count += 1
total_chestnuts = 0
while total_chestnuts < k:
time = heapq.heappop(pq)
total_chestnuts += 1
results.append(time)
return results
# Sample input parsing
t = 2
test_cases = [
{
'params': (3, 2, 5),
'T': [5, 1, 2],
'P': [1, 2, 1]
},
{
'params': (3, 2, 5),
'T': [5, 1, 2],
'P': [1, 1, 1]
}
]
results = min_time_to_collect_chestnuts(t, test_cases)
for result in results:
print(result)
Learning course: Placement preparation for Product companies
Problem Link: Squirrel and chestnut in Placement preparation for Product companies