My issue
Traceback (most recent call last):
File “/mnt/sol.py”, line 26, in
print(maxtaste(mp))
^^^^^^^^^^^^
File “/mnt/sol.py”, line 10, in maxtaste
max2 = -heapq.heappop(values)
^^^^^^^^^^^^^^^^^^^^^
IndexError: index out of range
My code
import heapq
def maxtaste(mp):
values = [ -v for v in mp.values() ]
heapq.heapify(values)
max1 = -heapq.heappop(values)
max2 = -heapq.heappop(values)
return max1 + max2
t = int(input())
for _ in range(t):
l,d = map(int, input().split() )
mp = {}
for _ in range(1):
k,v = map(int,input().split())
if k in mp:
mp[k] = map(mp[k],v)
else:
mp[k]=v
print(maxtaste(mp))
Learning course: Design and Analysis of Algorithms
Problem Link: https://www.codechef.com/learn/course/kl-daa/KLDAA2400H/problems/EATTWICE