( •̀ ω •́ )✧
SWEA 1959 본문
🔎 SWEA 1959. 두 개의 숫자열 (D2)
https://swexpertacademy.com/main/code/problem/problemDetail.do?contestProbId=AV5PpoFaAS4DFAUq
💡 풀이
case = int(input())
num = 1
while case > 0 :
case -= 1
n,m = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
max = -1000
if n < m :
for i in range(m - n + 1) :
result = [a[i] * b[i] for i in range(len(a))]
result = sum(result)
if result > max :
max = result
a.insert(0,0)
elif n > m :
for j in range(n - m + 1) :
result = [a[i] * b[i] for i in range(len(b))]
result = sum(result)
if result > max :
max = result
b.insert(0,0)
else :
result = [a[i] * b[i] for i in range(len(a))]
result = sum(result)
print(f'#{num} {max}')
num += 1
💭 TIL
- 리스트 a의 길이만큼 연속된 a, b 값에 대한 덧셈 / 곱셈
sum_list = [a[i] + b[i] for i in range(len(a))]
# [a[0]+b[0], a[1]+b[1], a[2]+b[2], ...]
multi_list = [a[i] * b[i] for i in range(len(a))]
# [a[0]*b[0], a[1]*b[1], a[2]*b[2], ...]
'🤖 알고리즘' 카테고리의 다른 글
BOJ 16118. 달빛 여우 (Python) / 다익스트라 (0) | 2023.08.31 |
---|---|
BOJ 1789. 수들의 합 (0) | 2023.08.10 |
BOJ 1456. 거의 소수 (0) | 2023.04.06 |
BOJ 2800. 괄호 제거 (0) | 2023.03.29 |
BOJ 14502. 연구소 (0) | 2023.03.23 |