98412024-03-11 14:42:0642Darabolás (50 pont)python3Time limit exceeded 46/50204ms44300 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
base46/50
1Accepted0/017ms11004 KiB
2Accepted0/0115ms34220 KiB
3Accepted1/118ms11500 KiB
4Accepted1/118ms12072 KiB
5Accepted1/117ms12156 KiB
6Accepted1/117ms12092 KiB
7Accepted1/118ms12504 KiB
8Accepted1/118ms12852 KiB
9Accepted1/118ms13108 KiB
10Accepted1/117ms13104 KiB
11Accepted1/118ms13364 KiB
12Accepted1/117ms13576 KiB
13Accepted1/117ms13272 KiB
14Accepted1/118ms13464 KiB
15Accepted1/118ms13684 KiB
16Accepted1/117ms13596 KiB
17Accepted1/119ms13776 KiB
18Accepted1/118ms13660 KiB
19Accepted2/218ms13936 KiB
20Accepted2/219ms14276 KiB
21Accepted3/326ms15728 KiB
22Accepted3/335ms17156 KiB
23Accepted4/467ms26380 KiB
24Accepted4/467ms25292 KiB
25Accepted4/4125ms38376 KiB
26Accepted4/4116ms37080 KiB
27Accepted4/4200ms44068 KiB
28Time limit exceeded0/4204ms44300 KiB