148552025-02-04 18:19:47horkaMaximális szorzat (50 pont)cpp17Runtime error 43/5046ms2876 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;
    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/01ms316 KiB
2Accepted0/01ms316 KiB
3Accepted0/01ms508 KiB
4Accepted0/01ms316 KiB
5Accepted0/04ms692 KiB
6Accepted2/21ms316 KiB
7Accepted2/21ms316 KiB
8Accepted2/21ms396 KiB
9Accepted2/21ms316 KiB
10Accepted2/24ms544 KiB
11Accepted2/243ms2612 KiB
12Accepted1/146ms2608 KiB
13Accepted1/11ms316 KiB
14Accepted1/14ms564 KiB
15Accepted1/19ms1216 KiB
16Accepted1/125ms1196 KiB
17Accepted1/112ms1140 KiB
18Accepted1/17ms1456 KiB
19Runtime error0/121ms1456 KiB
20Runtime error0/117ms1452 KiB
21Runtime error0/128ms1560 KiB
22Runtime error0/113ms1456 KiB
23Accepted1/141ms1852 KiB
24Accepted1/146ms2876 KiB
25Accepted2/21ms316 KiB
26Accepted2/23ms576 KiB
27Runtime error0/214ms960 KiB
28Runtime error0/114ms976 KiB
29Accepted2/27ms1032 KiB
30Accepted1/128ms1528 KiB
31Accepted1/116ms2732 KiB
32Accepted2/22ms316 KiB
33Accepted2/228ms1472 KiB
34Accepted1/129ms1520 KiB
35Accepted2/232ms1452 KiB
36Accepted2/228ms1508 KiB
37Accepted2/228ms1732 KiB
38Accepted2/228ms1456 KiB
39Accepted1/12ms316 KiB