98542024-03-12 00:24:1742Maximális szorzat (50 pont)python3Accepted 50/50223ms36636 KiB
# O(NlogN)
from sys import stdin, stdout
input=stdin.readline
mod=10**9+7

def solv():
    N,K,b = [int(x) for x in input().split()]
    A = [int(x) for x in input().split()]
    Aplus=[]
    Aminus=[]
    for a in A:
        if a<0:
            Aminus.append(a)
        else:
            Aplus.append(a)
    if len(Aminus)<b:
        print(-1)
        return
    Aminus.sort()
    for i in range(b,len(Aminus)):
        K+=Aminus[i]
    if K<0:
        print(-1)
        return
    prod=1
    for i in range(b):
        prod*=-Aminus[i]
        prod%=mod
    if len(Aplus)==0:
        if len(Aminus)==b:
            if -sum(Aminus)-b < K:
                print(-1)
                return
            Aminus.append(0)
            i=0
            while K>0:
                if i==0:
                    Aminus[0]+=1
                    K-=1
                    i+=1
                else:
                    if Aminus[i-1]>Aminus[i]:
                        Aminus[i]+=1
                        K-=1
                        i+=1
                    else:
                        i=0
            prod=1
            for i in range(len(Aminus)-1):
                prod*=-Aminus[i]
                prod%=mod
            print(prod)
            return
            
    for i in range(len(Aminus)-b):
        Aplus.append(0)
    Aplus.sort()
    Aplus.append(10**10)
    i=0
    while K>0:
        if i==0:
            Aplus[0]+=1
            K-=1
            i+=1
        else:
            if Aplus[i-1]>Aplus[i]:
                Aplus[i]+=1
                K-=1
                i+=1
            else:
                i=0
    for i in range(len(Aplus)-1):
        prod*=Aplus[i]
        prod%=mod
    print(prod)
    
solv()
SubtaskSumTestVerdictTimeMemory
base50/50
1Accepted0/018ms11652 KiB
2Accepted0/018ms12112 KiB
3Accepted0/017ms12340 KiB
4Accepted0/017ms12352 KiB
5Accepted0/028ms14632 KiB
6Accepted2/218ms12624 KiB
7Accepted2/218ms12972 KiB
8Accepted2/217ms13000 KiB
9Accepted2/218ms13460 KiB
10Accepted2/235ms15736 KiB
11Accepted2/2187ms35052 KiB
12Accepted1/1193ms34964 KiB
13Accepted1/120ms13868 KiB
14Accepted1/141ms15864 KiB
15Accepted1/150ms25016 KiB
16Accepted1/1137ms25396 KiB
17Accepted1/154ms25652 KiB
18Accepted1/143ms15928 KiB
19Accepted1/1216ms35796 KiB
20Accepted1/1202ms36148 KiB
21Accepted1/1223ms36104 KiB
22Accepted1/185ms30756 KiB
23Accepted1/1194ms36020 KiB
24Accepted1/1192ms36236 KiB
25Accepted2/228ms14640 KiB
26Accepted2/229ms16904 KiB
27Accepted2/2153ms24992 KiB
28Accepted1/1155ms25152 KiB
29Accepted2/239ms26020 KiB
30Accepted1/1202ms36076 KiB
31Accepted1/161ms36340 KiB
32Accepted2/2101ms15056 KiB
33Accepted2/2200ms36016 KiB
34Accepted1/1193ms36636 KiB
35Accepted2/2193ms36512 KiB
36Accepted2/2197ms36452 KiB
37Accepted2/2200ms36484 KiB
38Accepted2/2201ms36484 KiB
39Accepted1/1100ms14908 KiB