148572025-02-04 18:24:32horkaMaximális szorzat (50 pont)cpp17Runtime error 43/5045ms2788 KiB
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int MOD=1e9+7;
signed main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int n,k,b; cin>>n>>k>>b;
    vector<int> pos,neg;
    for(int i=0; i<n; i++)
    {
        int x; cin>>x;
        if(x<0) neg.push_back(x);
        else pos.push_back(x);
    }
    if(neg.size()<b)
    {
        cout<<"-1\n";
        return 0;
    }
    sort(neg.begin(),neg.end());
    int op=0;
    priority_queue<int> q;
    for(int &i:pos)
        q.push(-i);
    for(int i=b; i<neg.size(); i++)
    {
        op+=abs(neg[i]);
        q.push(0);
    }
    if(op>k)
    {
        cout<<"-1\n";
        return 0;
    }
    k-=op;
    if(b==n)
    {
        priority_queue<int> s;
        for(int i=0; i<n; i++)
            s.push(-neg[i]);
        while(k--)
        {
            int x=q.top();
            q.pop();
            x--;
            s.push(-x);
        }
        int ans=1;
        while(!s.empty())
        {
            ans=ans*q.top()%MOD;
            q.pop();
        }
        cout<<ans<<endl;
        return 0;
    }
    while(k--)
    {
        int x=q.top();
        q.pop();
        x=abs(x);
        x++;
        q.push(-x);
    }
    int ans=1;
    while(!q.empty())
    {
        int x=q.top();
        q.pop();
        x=abs(x);
        ans=ans*x%MOD;
    }
    for(int i=0; i<b; i++)
        ans=ans*abs(neg[i])%MOD;
    cout<<ans<<"\n";
}
SubtaskSumTestVerdictTimeMemory
base43/50
1Accepted0/01ms508 KiB
2Accepted0/01ms316 KiB
3Accepted0/01ms316 KiB
4Accepted0/01ms316 KiB
5Accepted0/04ms564 KiB
6Accepted2/21ms316 KiB
7Accepted2/21ms316 KiB
8Accepted2/21ms316 KiB
9Accepted2/21ms316 KiB
10Accepted2/24ms632 KiB
11Accepted2/241ms2748 KiB
12Accepted1/145ms2732 KiB
13Accepted1/11ms316 KiB
14Accepted1/14ms564 KiB
15Accepted1/19ms1140 KiB
16Accepted1/126ms1292 KiB
17Accepted1/110ms1004 KiB
18Accepted1/17ms1604 KiB
19Runtime error0/124ms2516 KiB
20Runtime error0/117ms2612 KiB
21Runtime error0/128ms2624 KiB
22Runtime error0/114ms2732 KiB
23Accepted1/141ms1964 KiB
24Accepted1/145ms2788 KiB
25Accepted2/21ms316 KiB
26Accepted2/23ms568 KiB
27Runtime error0/214ms1456 KiB
28Runtime error0/114ms1452 KiB
29Accepted2/27ms1012 KiB
30Accepted1/128ms1456 KiB
31Accepted1/116ms2712 KiB
32Accepted2/22ms320 KiB
33Accepted2/228ms1468 KiB
34Accepted1/128ms1460 KiB
35Accepted2/230ms1468 KiB
36Accepted2/228ms1460 KiB
37Accepted2/228ms1652 KiB
38Accepted2/228ms1456 KiB
39Accepted1/12ms316 KiB