98372024-03-11 14:20:4342Darabolás (50 pont)python3Time limit exceeded 42/50218ms44480 KiB
def solv():
    n,m=[int(x) for x in input().split()]
    N=[int(xx) for xx in input().split()]
    M=[int(xx) for xx 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/017ms11344 KiB
2Accepted0/0122ms34252 KiB
3Accepted1/117ms11400 KiB
4Accepted1/118ms12068 KiB
5Accepted1/118ms12132 KiB
6Accepted1/118ms12140 KiB
7Accepted1/118ms12672 KiB
8Accepted1/117ms12968 KiB
9Accepted1/117ms12884 KiB
10Accepted1/117ms12704 KiB
11Accepted1/117ms12656 KiB
12Accepted1/118ms12748 KiB
13Accepted1/117ms12624 KiB
14Accepted1/119ms13240 KiB
15Accepted1/118ms13192 KiB
16Accepted1/118ms13180 KiB
17Accepted1/119ms13652 KiB
18Accepted1/119ms13692 KiB
19Accepted2/219ms13884 KiB
20Accepted2/219ms13764 KiB
21Accepted3/327ms15148 KiB
22Accepted3/335ms16704 KiB
23Accepted4/470ms26172 KiB
24Accepted4/471ms25184 KiB
25Accepted4/4128ms38160 KiB
26Accepted4/4127ms36616 KiB
27Time limit exceeded0/4218ms44276 KiB
28Time limit exceeded0/4214ms44480 KiB