-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathicecreamparlor.py
52 lines (42 loc) · 1.32 KB
/
icecreamparlor.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#Mar marke samja. N2 implementation was cool. Hashmap was a bit fucking annoying.
#!/bin/python3
import math
import os
import random
import re
import sys
#
# Complete the 'icecreamParlor' function below.
#
# The function is expected to return an INTEGER_ARRAY.
# The function accepts following parameters:
# 1. INTEGER m
# 2. INTEGER_ARRAY arr
#
def icecreamParlor(m, arr):
# Write your code here
parlor=dict()
for i in range(len(arr)):
if arr[i] not in parlor:
parlor[m-arr[i]]=i+1
else:
# x=sorted(i+1,parlor[arr[i]])
return sorted([i+1, parlor[arr[i]]])
# def icecreamParlor(m, arr):
# test = dict()
# for i in range(len(arr)):
# if arr[i] not in test:
# test[m-arr[i]] = i+1 #dollar match amount is key, 1based index is value
# else:
# return sorted([i+1, test[arr[i]]])
if __name__ == '__main__':
fptr = open(os.environ['OUTPUT_PATH'], 'w')
t = int(input().strip())
for t_itr in range(t):
m = int(input().strip())
n = int(input().strip())
arr = list(map(int, input().rstrip().split()))
result = icecreamParlor(m, arr)
fptr.write(' '.join(map(str, result)))
fptr.write('\n')
fptr.close()