본문 바로가기
Algorithm/swea

[파이썬]swea 1959: 두 개의 숫자열

by 갈잃자 2023. 2. 11.

https://swexpertacademy.com/main/code/problem/problemDetail.do?problemLevel=2&contestProbId=AV5PpoFaAS4DFAUq&categoryId=AV5PpoFaAS4DFAUq&categoryType=CODE&problemTitle=&orderBy=FIRST_REG_DATETIME&selectCodeLang=ALL&select-1=2&pageSize=10&pageIndex=2 

 

SW Expert Academy

SW 프로그래밍 역량 강화에 도움이 되는 다양한 학습 컨텐츠를 확인하세요!

swexpertacademy.com


단순 구현문제

 

a와 b의 길이를 비교하여 idx를 옮기며 max값을 갖는 경우를 확인

t = int(input())
for tc in range(1,t+1):
    n,m = map(int,input().split())
    a = list(map(int,input().split()))
    b = list(map(int,input().split()))
    if n > m:
        n,m = m,n

    if len(b) < len(a):
        b,a = a,b
    Max = -21e8
    c=int(abs(m-n))+1
    for i in range(c):
        result = 0
        for j in range(n):
            result +=b[i+j] * a[j]
        Max = max(Max, result)

    print(f"#{tc} {Max}")

댓글