We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.

# ThinhNguyen97"""IMissThoseMomentsISpentWithYouKitchenTableMirrorSofa"""# Python is scripting language use interpreter# import numpy as np# import matplotlib.pyplot as plt# import pandas as pdfrommathimport*frombuiltinsimportstaticmethodfromcollectionsimportCounterfromcollectionsimportdefaultdictfromcollectionsimportnamedtuplefromcollectionsimportdequefromqueueimportLifoQueueimportheapqimportfunctoolsimporthashlibfromdatetimeimportdatetime,timedeltaimportjsonimportrefromitertoolsimport*importqueuefrombisectimportbisect_leftdefsolve(m,cost):# Create a dictionary to store the indices of flavors based on their pricesflavor_indices={}# Iterate through the list of costsforiinrange(len(cost)):# Calculate the remaining amount of money after purchasing the current flavorremaining_money=m-cost[i]# Check if the remaining money corresponds to the price of any previously visited flavorifremaining_moneyinflavor_indices:# If found, return the indices of the two flavors (1-based indexing)return[flavor_indices[remaining_money]+1,i+1]else:# If not found, store the current flavor's index in the dictionaryflavor_indices[cost[i]]=idefmain():t=int(input().strip())for_inrange(t):m=int(input().strip())n=int(input().strip())arr=list(map(int,input().rstrip().split()))result=solve(m,arr)print(result[0],result[1])if__name__=='__main__':main()

## Ice Cream Parlor

You are viewing a single comment's thread. Return to all comments →