Ice Cream Parlor

  • + 0 comments
    # ThinhNguyen97
    """
    I Miss Those Moments I Spent With You
    Kitchen
    Table
    Mirror
    Sofa
    """
    # Python is scripting language use interpreter
    # import numpy as np
    # import matplotlib.pyplot as plt
    # import pandas as pd
    
    
    from math import *
    from builtins import staticmethod
    from collections import Counter
    from collections import defaultdict
    from collections import namedtuple
    from collections import deque
    from queue import LifoQueue
    import heapq
    import functools
    import hashlib
    from datetime import datetime, timedelta
    import json
    import re
    from itertools import *
    import queue
    from bisect import bisect_left
    
    
    def solve(m, cost):
        # Create a dictionary to store the indices of flavors based on their prices
        flavor_indices = {}
    
        # Iterate through the list of costs
        for i in range(len(cost)):
            # Calculate the remaining amount of money after purchasing the current flavor
            remaining_money = m - cost[i]
    
            # Check if the remaining money corresponds to the price of any previously visited flavor
            if remaining_money in flavor_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 dictionary
                flavor_indices[cost[i]] = i
    
    
    def main():
        t = int(input().strip())
        for _ in range(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()