98442024-03-11 14:55:2342Darabolás (50 pont)python3Accepted 50/50197ms43152 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=1
    mcount=1
    res=0
    i=j=0
    for _ in range(n+m-2):
        if N[i]>M[j]:
            res+=N[i]*mcount
            i+=1
            ncount+=1
        else:
            res+=M[j]*ncount
            j+=1
            mcount+=1
    print(res)

solv()
SubtaskSumTestVerdictTimeMemory
base50/50
1Accepted0/017ms11288 KiB
2Accepted0/0112ms34240 KiB
3Accepted1/117ms11500 KiB
4Accepted1/117ms11840 KiB
5Accepted1/118ms12188 KiB
6Accepted1/118ms11952 KiB
7Accepted1/118ms12628 KiB
8Accepted1/117ms12864 KiB
9Accepted1/117ms12656 KiB
10Accepted1/118ms12940 KiB
11Accepted1/118ms12896 KiB
12Accepted1/117ms12844 KiB
13Accepted1/117ms12792 KiB
14Accepted1/118ms13024 KiB
15Accepted1/118ms13124 KiB
16Accepted1/117ms13180 KiB
17Accepted1/118ms13292 KiB
18Accepted1/118ms13180 KiB
19Accepted2/218ms13548 KiB
20Accepted2/218ms13392 KiB
21Accepted3/325ms14588 KiB
22Accepted3/332ms16012 KiB
23Accepted4/464ms25328 KiB
24Accepted4/465ms24632 KiB
25Accepted4/4118ms37528 KiB
26Accepted4/4112ms35980 KiB
27Accepted4/4192ms42936 KiB
28Accepted4/4197ms43152 KiB