98432024-03-11 14:43:2942Darabolás (50 pont)python3Time limit exceeded 42/50209ms43268 KiB
from sys import stdin
input=stdin.readline

def solv():
    n,m=map(int,input().split())
    #N=[int(x) for x in input().split()]
    N=list(map(int,input().split()))
    M=list(map(int,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)

solv()
SubtaskSumTestVerdictTimeMemory
base42/50
1Accepted0/017ms11156 KiB
2Accepted0/0119ms33988 KiB
3Accepted1/117ms11664 KiB
4Accepted1/118ms12008 KiB
5Accepted1/118ms12364 KiB
6Accepted1/118ms12148 KiB
7Accepted1/118ms12316 KiB
8Accepted1/117ms12192 KiB
9Accepted1/118ms12408 KiB
10Accepted1/118ms12608 KiB
11Accepted1/118ms12804 KiB
12Accepted1/117ms12672 KiB
13Accepted1/117ms12404 KiB
14Accepted1/118ms12852 KiB
15Accepted1/118ms13068 KiB
16Accepted1/118ms13272 KiB
17Accepted1/119ms13604 KiB
18Accepted1/118ms13388 KiB
19Accepted2/218ms13648 KiB
20Accepted2/219ms13816 KiB
21Accepted3/326ms15188 KiB
22Accepted3/334ms16468 KiB
23Accepted4/468ms25724 KiB
24Accepted4/467ms24644 KiB
25Accepted4/4120ms37676 KiB
26Accepted4/4119ms36164 KiB
27Time limit exceeded0/4209ms43268 KiB
28Time limit exceeded0/4204ms43076 KiB