246452026-02-13 09:02:35szjMaximális szorzat (50 pont)cpp11Accepted 50/5059ms2744 KiB
#include <bits/stdc++.h>
#define ll long long
#define blugy %1000000007
using namespace std;
class cucc
{
public:
    bool operator()(const ll &x, const ll &y)const
    {
        return x < y;
    }
};
int main()
{
    //ifstream cin("f.txt");
    ios::sync_with_stdio(0);
    cin.tie(0);
    ll n, k, b, i, a, sum=1, parsum=0, el;
    cin >> n >> k >> b;
    bool cuccli=0;
    priority_queue<ll, vector<ll>, cucc> nega;
    priority_queue<ll, vector<ll>, greater<ll>> pozi;
    for(i=0; i<n; i++)
    {
        cin >> a;
        if(a<0)nega.push(a);
        else pozi.push(a);
    }
    if(b>nega.size())
    {
        cout <<-1;
        return 0;
    }
    while(nega.size()>b)
    {
        k+=nega.top();
        nega.pop();
        pozi.push(0);
    }
    if(k<0)
    {
        cout << -1;
        return 0;
    }
    if(pozi.empty())
    {
        while(!nega.empty())
        {
            pozi.push(nega.top());
            nega.pop();
            cuccli=1;
        }
    }
    if(!pozi.empty())
    {
        while(k!=0)
        {
            a = pozi.top();
            if(a+1>=0 && cuccli)
            {
                cout << -1;
                return 0;
            }
            pozi.pop();
            pozi.push(a+1);
            k--;
        }
    }
    while(!pozi.empty())
    {
        sum=(sum*(abs(pozi.top())blugy))blugy;
        pozi.pop();
    }
    while(!nega.empty())
    {
        sum=(sum*(abs(nega.top()))blugy)blugy;
        nega.pop();
    }
    cout << sum;
    return 0;
}
SubtaskSumTestVerdictTimeMemory
base50/50
1Accepted0/01ms316 KiB
2Accepted0/01ms316 KiB
3Accepted0/01ms316 KiB
4Accepted0/01ms316 KiB
5Accepted0/04ms564 KiB
6Accepted2/21ms316 KiB
7Accepted2/21ms560 KiB
8Accepted2/21ms508 KiB
9Accepted2/21ms436 KiB
10Accepted2/24ms564 KiB
11Accepted2/241ms1408 KiB
12Accepted1/145ms1408 KiB
13Accepted1/11ms316 KiB
14Accepted1/14ms564 KiB
15Accepted1/18ms928 KiB
16Accepted1/128ms1132 KiB
17Accepted1/18ms948 KiB
18Accepted1/17ms948 KiB
19Accepted1/157ms2628 KiB
20Accepted1/150ms2716 KiB
21Accepted1/159ms2744 KiB
22Accepted1/121ms2736 KiB
23Accepted1/146ms1332 KiB
24Accepted1/146ms1484 KiB
25Accepted2/21ms316 KiB
26Accepted2/24ms564 KiB
27Accepted2/235ms1604 KiB
28Accepted1/135ms1464 KiB
29Accepted2/28ms1012 KiB
30Accepted1/135ms1512 KiB
31Accepted1/114ms1588 KiB
32Accepted2/22ms316 KiB
33Accepted2/235ms1596 KiB
34Accepted1/135ms1568 KiB
35Accepted2/237ms1352 KiB
36Accepted2/235ms1456 KiB
37Accepted2/235ms1460 KiB
38Accepted2/235ms1584 KiB
39Accepted1/12ms316 KiB