테스트케이스 수
내가 가진 돈
아이스크림 가격 수
아이스크림 금액 금액 금액 금액 [ ]
출력은 인덱스+1를 반환하는 거임 (가격이 아니라 가격의 번호)
아이스크림 가격을 조합해서
내가 원하는 금액 맞추는 것
from itertools import permutations
def icecreamParlor(m, arr, n):
answer = []
visit = [False]*(n)
for i in permutations(arr, 2):
if sum(i) == m:
ans = i
break
for i in range(n):
if arr[i] == ans[0] and visit[i] == False:
answer.append(i+1)
visit[i] = True
if arr[i] == ans[1] and visit[i] == False:
answer.append(i+1)
visit[i] = True
return answer
print(" ".join(map(str,icecreamParlor(4, [1, 4, 5, 3, 2], 5))))
print(" ".join(map(str,icecreamParlor(4, [2, 2, 4, 3], 4))))
#!/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
#
from itertools import permutations
def icecreamParlor(m, arr, n):
answer = []
visit = [False]*(n)
for i in permutations(arr, 2):
if sum(i) == m:
ans = i
break
for i in range(n):
if arr[i] == ans[0] and visit[i] == False:
answer.append(i+1)
visit[i] = True
if arr[i] == ans[1] and visit[i] == False:
answer.append(i+1)
visit[i] = True
return answer
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, n)
fptr.write(' '.join(map(str, result)))
fptr.write('\n')
fptr.close()