98522024-03-12 00:16:0442Maximális szorzat (50 pont)python3Wrong answer 7/50218ms35996 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(-11)
        return
    Aminus.sort()
    #print(Aminus,K,b)
    for i in range(b,len(Aminus)):
        K+=Aminus[i]
    if K<0:
        print(-111)
        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
base7/50
1Wrong answer0/017ms11828 KiB
2Wrong answer0/018ms12180 KiB
3Wrong answer0/017ms12336 KiB
4Wrong answer0/017ms12652 KiB
5Wrong answer0/028ms14984 KiB
6Wrong answer0/217ms12748 KiB
7Wrong answer0/217ms12672 KiB
8Wrong answer0/218ms12872 KiB
9Wrong answer0/219ms13692 KiB
10Wrong answer0/235ms15704 KiB
11Wrong answer0/2208ms35296 KiB
12Wrong answer0/1209ms35200 KiB
13Wrong answer0/121ms13768 KiB
14Wrong answer0/143ms16208 KiB
15Wrong answer0/148ms24852 KiB
16Wrong answer0/1137ms25176 KiB
17Wrong answer0/154ms25536 KiB
18Wrong answer0/148ms15064 KiB
19Accepted1/1214ms35564 KiB
20Accepted1/1204ms35800 KiB
21Accepted1/1218ms35652 KiB
22Accepted1/185ms29972 KiB
23Wrong answer0/1204ms35664 KiB
24Wrong answer0/1210ms35432 KiB
25Wrong answer0/228ms14016 KiB
26Wrong answer0/229ms16480 KiB
27Accepted2/2155ms24860 KiB
28Accepted1/1156ms24792 KiB
29Wrong answer0/239ms25568 KiB
30Wrong answer0/1202ms35996 KiB
31Wrong answer0/161ms35960 KiB
32Wrong answer0/2101ms14264 KiB
33Wrong answer0/2199ms35732 KiB
34Wrong answer0/1193ms35776 KiB
35Wrong answer0/2192ms35760 KiB
36Wrong answer0/2196ms35528 KiB
37Wrong answer0/2194ms35836 KiB
38Wrong answer0/2202ms35896 KiB
39Wrong answer0/1100ms14340 KiB