98532024-03-12 00:16:4442Maximális szorzat (50 pont)python3Wrong answer 12/50218ms36432 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()]
    #print(0)
    #return
    #print(A,N,K,b)
    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()
    #print(Aminus,K,b)
    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
            #print(Aminus)
            for i in range(len(Aminus)-1):
                prod*=-Aminus[i]
                prod%=mod
            print(prod)
            return
    #print(K,Aplus,prod)
    for i in range(len(Aplus)-1):
        prod*=Aplus[i]
        prod%=mod
    print(prod)
            
    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
    #print(K,Aplus,prod)
    for i in range(len(Aplus)-1):
        prod*=Aplus[i]
        prod%=mod
    print(prod)
    
solv()

SubtaskSumTestVerdictTimeMemory
base12/50
1Wrong answer0/019ms11612 KiB
2Wrong answer0/018ms11792 KiB
3Wrong answer0/017ms12124 KiB
4Wrong answer0/017ms12300 KiB
5Wrong answer0/028ms14364 KiB
6Wrong answer0/217ms12452 KiB
7Wrong answer0/218ms12796 KiB
8Wrong answer0/218ms12784 KiB
9Wrong answer0/219ms13436 KiB
10Wrong answer0/235ms15412 KiB
11Wrong answer0/2208ms34968 KiB
12Wrong answer0/1209ms35068 KiB
13Wrong answer0/120ms13672 KiB
14Wrong answer0/141ms15560 KiB
15Accepted1/150ms24676 KiB
16Wrong answer0/1137ms24628 KiB
17Accepted1/152ms25188 KiB
18Wrong answer0/148ms15124 KiB
19Accepted1/1215ms35380 KiB
20Accepted1/1202ms35816 KiB
21Accepted1/1218ms35312 KiB
22Accepted1/183ms30060 KiB
23Wrong answer0/1209ms35480 KiB
24Wrong answer0/1214ms35872 KiB
25Wrong answer0/228ms14016 KiB
26Wrong answer0/230ms16196 KiB
27Accepted2/2155ms24636 KiB
28Accepted1/1155ms24524 KiB
29Accepted2/239ms25212 KiB
30Wrong answer0/1202ms35708 KiB
31Accepted1/164ms35788 KiB
32Wrong answer0/2108ms14672 KiB
33Wrong answer0/2199ms35892 KiB
34Wrong answer0/1194ms36076 KiB
35Wrong answer0/2194ms36228 KiB
36Wrong answer0/2200ms36136 KiB
37Wrong answer0/2197ms36356 KiB
38Wrong answer0/2206ms36432 KiB
39Wrong answer0/1100ms15004 KiB