189362025-11-12 19:50:56KristófMaximális szorzat (50 pont)python3Runtime error 0/5017ms3236 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)
        {
        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)
        {
        priority_queue<int> minn;
        while(!negativ.empty())
            {
            minn.push(negativ.top()*-1);negativ.pop();
            }
        while(k > 0 && minn.top()!=-1)
            {
            k--;
            x=minn.top()*-1;minn.pop();
            x++;
            minn.push(x*-1);
            }
        if(negativ.top() == 1 && k>0)
            {
            cout<<-1;
            return 0;
            }
        while(!minn.empty())
            {
            negativ.push(minn.top()*-1);minn.pop();
            }
        }
    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
base0/50
1Runtime error0/016ms2860 KiB
2Runtime error0/016ms2868 KiB
3Runtime error0/014ms3060 KiB
4Runtime error0/016ms2868 KiB
5Runtime error0/016ms3036 KiB
6Runtime error0/214ms3032 KiB
7Runtime error0/216ms2896 KiB
8Runtime error0/214ms2848 KiB
9Runtime error0/216ms2868 KiB
10Runtime error0/216ms2872 KiB
11Runtime error0/216ms2876 KiB
12Runtime error0/116ms2888 KiB
13Runtime error0/116ms2952 KiB
14Runtime error0/116ms3004 KiB
15Runtime error0/116ms2904 KiB
16Runtime error0/114ms2896 KiB
17Runtime error0/116ms3068 KiB
18Runtime error0/117ms3056 KiB
19Runtime error0/117ms2984 KiB
20Runtime error0/117ms2868 KiB
21Runtime error0/114ms2952 KiB
22Runtime error0/114ms2884 KiB
23Runtime error0/116ms2872 KiB
24Runtime error0/114ms2868 KiB
25Runtime error0/216ms3048 KiB
26Runtime error0/216ms3064 KiB
27Runtime error0/216ms2872 KiB
28Runtime error0/114ms2868 KiB
29Runtime error0/214ms3044 KiB
30Runtime error0/116ms3040 KiB
31Runtime error0/114ms3084 KiB
32Runtime error0/216ms3040 KiB
33Runtime error0/214ms3236 KiB
34Runtime error0/116ms2872 KiB
35Runtime error0/216ms2868 KiB
36Runtime error0/214ms2884 KiB
37Runtime error0/216ms2824 KiB
38Runtime error0/214ms2872 KiB
39Runtime error0/116ms2820 KiB