98422024-03-11 14:42:4942Darabolás (50 pont)python3Time limit exceeded 42/50209ms43500 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/017ms11184 KiB
2Accepted0/0119ms34088 KiB
3Accepted1/118ms11792 KiB
4Accepted1/118ms12248 KiB
5Accepted1/118ms12420 KiB
6Accepted1/118ms12256 KiB
7Accepted1/117ms12652 KiB
8Accepted1/118ms12388 KiB
9Accepted1/118ms12452 KiB
10Accepted1/118ms12472 KiB
11Accepted1/118ms12712 KiB
12Accepted1/118ms12548 KiB
13Accepted1/117ms12540 KiB
14Accepted1/117ms12816 KiB
15Accepted1/117ms13156 KiB
16Accepted1/117ms13508 KiB
17Accepted1/119ms13744 KiB
18Accepted1/118ms13528 KiB
19Accepted2/218ms13772 KiB
20Accepted2/219ms13716 KiB
21Accepted3/326ms15132 KiB
22Accepted3/335ms16656 KiB
23Accepted4/467ms25984 KiB
24Accepted4/464ms24684 KiB
25Accepted4/4120ms38088 KiB
26Accepted4/4119ms36648 KiB
27Time limit exceeded0/4209ms43500 KiB
28Time limit exceeded0/4207ms43436 KiB