98392024-03-11 14:25:2042Darabolás (50 pont)pypy3Runtime error 34/5090ms100356 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
base34/50
1Accepted0/046ms87500 KiB
2Runtime error0/071ms99196 KiB
3Accepted1/156ms94104 KiB
4Accepted1/150ms94236 KiB
5Accepted1/159ms93824 KiB
6Accepted1/159ms93788 KiB
7Accepted1/152ms87820 KiB
8Accepted1/159ms93956 KiB
9Accepted1/159ms94192 KiB
10Accepted1/154ms94100 KiB
11Accepted1/150ms94056 KiB
12Accepted1/159ms94224 KiB
13Accepted1/152ms87308 KiB
14Accepted1/154ms94140 KiB
15Accepted1/152ms94132 KiB
16Accepted1/161ms94124 KiB
17Accepted1/164ms94168 KiB
18Accepted1/164ms93904 KiB
19Accepted2/259ms94164 KiB
20Accepted2/264ms94348 KiB
21Accepted3/363ms95416 KiB
22Accepted3/375ms95984 KiB
23Accepted4/490ms100012 KiB
24Accepted4/489ms98832 KiB
25Runtime error0/479ms100356 KiB
26Runtime error0/467ms95332 KiB
27Runtime error0/475ms95468 KiB
28Runtime error0/467ms95408 KiB