189282025-11-12 17:57:15KristófMaximális szorzat (50 pont)cpp17Wrong answer 19/5082ms1040 KiB
#include <iostream>
#include <vector>
#include <queue>
using namespace std;

long long mod=1000000007;


int main()
{
    int n,k,b;
    cin>>n>>k>>b;
    priority_queue<int> negativ,poz;
    int x;
    for(int i=0;i<n;i++)
        {
        cin>>x;
        if(x>-1)
            {
            poz.push(x*-1);
            }
        else
            {
            negativ.push(x);
            }
        }
    if(negativ.size()<b)
        {
        cout<<-1;
        return 0;
        }
    if(negativ.size() == b && n!=b)
        {
        while(k--)
            {
            x=poz.top()*-1;poz.pop();
            x++;
            poz.push(x*-1);
            }
        }
    else if(negativ.size() > b)
        {
        return 0;
        while(negativ.size()!=b && negativ.size()>0)
            {
            k+=negativ.top();
            if(k<0)
                {
                cout<<-1;
                return 0;
                }
            poz.push(0);
            negativ.pop();
            }
        while(k-- && !poz.empty())
            {
            x=poz.top()*-1;poz.pop();
            x++;
            poz.push(x*-1);
            }
        }
    else if(n==b)
        {
        while(k-- && negativ.top()!=-1)
            {
            x=negativ.top();
            x++;
            negativ.push(x);
            negativ.pop();
            }
        if(negativ.top() == -1 && k>0)
            {
            cout<<-1;
            return 0;
            }
        }
    long long ans=1;
    while(!poz.empty())
        {
        ans *=  (-poz.top() % mod);
        ans = ans % mod;
        poz.pop();
        }
    while(!negativ.empty())
        {
        ans*=negativ.top();
        ans = ans % mod;
        negativ.pop();
        }
    cout<<ans;
    return 0;
}
SubtaskSumTestVerdictTimeMemory
base19/50
1Accepted0/01ms316 KiB
2Wrong answer0/01ms316 KiB
3Accepted0/01ms316 KiB
4Wrong answer0/01ms508 KiB
5Wrong answer0/03ms316 KiB
6Accepted2/21ms316 KiB
7Accepted2/21ms316 KiB
8Accepted2/21ms316 KiB
9Accepted2/21ms316 KiB
10Accepted2/27ms316 KiB
11Accepted2/271ms992 KiB
12Accepted1/176ms940 KiB
13Wrong answer0/11ms568 KiB
14Wrong answer0/14ms316 KiB
15Wrong answer0/117ms564 KiB
16Wrong answer0/117ms624 KiB
17Wrong answer0/117ms688 KiB
18Wrong answer0/19ms688 KiB
19Wrong answer0/167ms956 KiB
20Wrong answer0/127ms944 KiB
21Wrong answer0/182ms840 KiB
22Accepted1/123ms980 KiB
23Accepted1/178ms900 KiB
24Accepted1/176ms1040 KiB
25Wrong answer0/21ms328 KiB
26Wrong answer0/24ms316 KiB
27Wrong answer0/246ms772 KiB
28Wrong answer0/146ms684 KiB
29Accepted2/218ms640 KiB
30Wrong answer0/150ms804 KiB
31Wrong answer0/135ms940 KiB
32Wrong answer0/21ms328 KiB
33Wrong answer0/250ms1024 KiB
34Accepted1/171ms1000 KiB
35Wrong answer0/250ms1036 KiB
36Wrong answer0/250ms944 KiB
37Wrong answer0/250ms1024 KiB
38Wrong answer0/250ms948 KiB
39Wrong answer0/11ms316 KiB