98402024-03-11 14:32:0142Darabolás (50 pont)python3Time limit exceeded 42/50207ms43820 KiB
from sys import stdin
input=stdin.readline

def solv():
    n,m=[int(x) for x in input().split()]
    N=list(map(int,input().split()))
    #N=[int(x) for x in 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/017ms11240 KiB
2Accepted0/0115ms34264 KiB
3Accepted1/118ms11788 KiB
4Accepted1/118ms12256 KiB
5Accepted1/117ms12476 KiB
6Accepted1/117ms12100 KiB
7Accepted1/117ms12412 KiB
8Accepted1/117ms12572 KiB
9Accepted1/117ms12840 KiB
10Accepted1/117ms12940 KiB
11Accepted1/117ms12924 KiB
12Accepted1/118ms13100 KiB
13Accepted1/117ms12916 KiB
14Accepted1/117ms13208 KiB
15Accepted1/117ms13260 KiB
16Accepted1/117ms13252 KiB
17Accepted1/119ms13836 KiB
18Accepted1/118ms13768 KiB
19Accepted2/218ms14060 KiB
20Accepted2/218ms14124 KiB
21Accepted3/326ms14948 KiB
22Accepted3/334ms16684 KiB
23Accepted4/465ms26144 KiB
24Accepted4/464ms25132 KiB
25Accepted4/4120ms36836 KiB
26Accepted4/4119ms36360 KiB
27Time limit exceeded0/4207ms43712 KiB
28Time limit exceeded0/4203ms43820 KiB