200852026-01-01 11:42:24marnorlorOsztozkodás (75 pont)python3Runtime error 5/75578ms15076 KiB
def osztozas(N: int, K: int, A: list):
    ajandekA=[]
    ajandekB=[]
    max2=0
    kOsszeg=0
    osszegA=0
    osszegB=0
    j=0
    A.sort(reverse=True)
    while True:
        max2=A[j]
        if len(A)<=K:
            for i in A:
                kOsszeg=kOsszeg+i
            if kOsszeg<max2:
                if j % 2==0:
                    osszegA=osszegA+max2
                if j % 2==1:
                    osszegB=osszegB+max2
                #A.remove(max2)
            else:
                A=[]
                if j % 2==0:
                    osszegA=osszegA+kOsszeg
                if j % 2==1:
                    osszegB=osszegB+kOsszeg
        else:
            if j % 2==0:
                    osszegA=osszegA+max2
            if j % 2==1:
                    osszegB=osszegB+max2
            #A.remove(max2)
        kOsszeg=0
        if len(A)==0:
            break
        j=j+1
    return osszegA, osszegB

def test():
    a, b=osztozas(5, 3, [-2, 3, -1, 4, 5])
    assert 6==a
    assert 3==b

    a, b=osztozas(5, 3, [1, 4, 2, 4, 5])
    print(a, b)
    assert 12==a
    assert 4==b  
    a, b=osztozas(5, 3, [2, 3, 1, 5, 4])
    assert 11==a
    assert 4==b

    a, b=osztozas(5, 0, [2, 3, 1, 5, 4])
    assert 9==a
    assert 6==b

    a, b=osztozas(2, 2, [-5, 3])
    assert 3==a
    assert -5==b

    N=100000
    E=[0]*N
    for i in range(0, N):
        E[i]=i
    a, b=osztozas(N, 0, E)
    assert 2500000000==a
    assert 2499950000==b
    
    a, b=osztozas(20, 5, [7, 8, -4, 3, 10, 7, 4, 10, 6, 1, -1, 4, -1, -2, 3, -1, 4, -2, -3, 5])
    assert 32==a
    assert 26==b

def futtatas():
    N, K=map(int,input().split())
    A=list(map(int,input().split()))
    a, b=osztozas(N, K, A)
    print(a, b)

#test()
futtatas()
SubtaskSumTestVerdictTimeMemory
base5/75
1Runtime error0/017ms3320 KiB
2Runtime error0/017ms3124 KiB
3Runtime error0/217ms3112 KiB
4Runtime error0/316ms3124 KiB
5Runtime error0/317ms3120 KiB
6Runtime error0/217ms3516 KiB
7Runtime error0/318ms3604 KiB
8Runtime error0/218ms3636 KiB
9Runtime error0/318ms3600 KiB
10Runtime error0/219ms3692 KiB
11Runtime error0/319ms3520 KiB
12Runtime error0/1105ms14240 KiB
13Runtime error0/2108ms14228 KiB
14Runtime error0/1107ms14168 KiB
15Accepted2/283ms14196 KiB
16Runtime error0/193ms13632 KiB
17Runtime error0/2103ms14840 KiB
18Runtime error0/198ms13628 KiB
19Runtime error0/270ms11816 KiB
20Runtime error0/268ms11816 KiB
21Runtime error0/3111ms14860 KiB
22Runtime error0/2104ms14792 KiB
23Runtime error0/3101ms14984 KiB
24Runtime error0/2104ms14796 KiB
25Runtime error0/3108ms14792 KiB
26Runtime error0/2103ms15076 KiB
27Runtime error0/3114ms14144 KiB
28Time limit exceeded0/2578ms14148 KiB
29Runtime error0/3104ms14180 KiB
30Runtime error0/317ms3124 KiB
31Runtime error0/317ms3232 KiB
32Accepted3/316ms3128 KiB
33Wrong answer0/317ms3124 KiB
34Runtime error0/317ms3144 KiB