98382024-03-11 14:24:5542Darabolás (50 pont)python3Time limit exceeded 42/50216ms43676 KiB
from sys import stdin
input=stdin.readline

def solv():
    n,m=[int(x) for x in input().split()]
    N=[int(x) for x in input().split()]
    M=[int(x) for x in input().split()]
    N.sort(reverse=True)
    M.sort(reverse=True)
    N.append(-1)
    M.append(-1)
    ncount=0
    mcount=0
    res=0
    i=j=0
    for _ in range(n+m-2):
        if N[i]>M[j]:
            res+=N[i]*(mcount+1)
            i+=1
            ncount+=1
        else:
            res+=M[j]*(ncount+1)
            j+=1
            mcount+=1
    print(res,end="\r\n")

solv()
SubtaskSumTestVerdictTimeMemory
base42/50
1Accepted0/018ms11064 KiB
2Accepted0/0123ms34060 KiB
3Accepted1/117ms11452 KiB
4Accepted1/118ms11740 KiB
5Accepted1/118ms11868 KiB
6Accepted1/118ms11756 KiB
7Accepted1/118ms12220 KiB
8Accepted1/118ms12392 KiB
9Accepted1/117ms12420 KiB
10Accepted1/118ms12540 KiB
11Accepted1/117ms12456 KiB
12Accepted1/118ms12744 KiB
13Accepted1/117ms12944 KiB
14Accepted1/118ms13200 KiB
15Accepted1/118ms13496 KiB
16Accepted1/118ms13252 KiB
17Accepted1/118ms13648 KiB
18Accepted1/118ms13692 KiB
19Accepted2/218ms13712 KiB
20Accepted2/219ms13804 KiB
21Accepted3/327ms15076 KiB
22Accepted3/335ms16624 KiB
23Accepted4/471ms26096 KiB
24Accepted4/468ms24992 KiB
25Accepted4/4123ms38136 KiB
26Accepted4/4127ms36672 KiB
27Time limit exceeded0/4216ms43652 KiB
28Time limit exceeded0/4210ms43676 KiB