155622025-02-20 12:53:53xxxMaximális szorzat (50 pont)cpp17Accepted 50/5054ms3544 KiB
#include <bits/stdc++.h>
using namespace std;

#define int long long

const int INF = 3000000;
const int MOD = 1e9+7;


signed main() {
    ios_base::sync_with_stdio(0);
    cout.tie(0);
    int n, k, b;
    cin >> n >> k >> b;

    vector<int> a(n+1);
    vector<int> negv;
    priority_queue<int, vector<int>, greater<int>> pq;
    int negc = 0, negmax = -INF;
    for(int i = 1; i <= n; i++) {
        cin >> a[i];
        if (a[i] < 0) {
            negc++;
            negv.push_back((-1)*a[i]);
        } else {
            pq.push(a[i]);
        }
    }

    if (negc < b) {
        cout << -1 << endl;
        return 0;
    }
    sort(negv.begin(), negv.end());

    int bc = negc-b, kc = k;
    for(int i = 0; i < negc; i++) {
        if (bc > 0) {
            if (negv[i] > kc) {
                cout << -1 << endl;
                return 0;
            } else {
                kc -= negv[i];
                bc--;
                negv[i] = 0;
                pq.push(0);
            }
        }
    }

    if (pq.empty()) {
        priority_queue<int, vector<int>, greater<int> > pq2;
        for(int i = 0; i < negc; i++) {
            pq2.push(negv[i]*(-1));
        }

        while(!pq2.empty() && kc > 0) {
            int X = pq2.top();
            //cout << X << ' ';
            pq2.pop();
            if (X == -1) {
                cout << -1 << endl;
                return 0;
            }
            pq2.push(X+1);
            kc--;
        }
        /*4 4 4
-3 -2 -1 -1*/

        int ans = 1;

        while(!pq2.empty()) {
            ans *= pq2.top();
            pq2.pop();
            ans %= MOD;
        }
        cout << ans << endl;

        return 0;

    }

    while (kc > 0) {
        int X = pq.top();
        pq.pop();
        pq.push(X+1);
        kc--;
    }

    int ans = 1;

    for(int i = 0; i < negc; i++) {
        if (negv[i] != 0) {
            ans *= negv[i];
            ans %= MOD;
        }
    }
    //cout << ans << "n\n";

    while(!pq.empty()) {
        int X = pq.top();
        ans *= X;
        ans %= MOD;
        pq.pop();
    }
    cout << ans << endl;

}
SubtaskSumTestVerdictTimeMemory
base50/50
1Accepted0/01ms316 KiB
2Accepted0/01ms500 KiB
3Accepted0/01ms332 KiB
4Accepted0/01ms316 KiB
5Accepted0/04ms608 KiB
6Accepted2/21ms316 KiB
7Accepted2/21ms316 KiB
8Accepted2/21ms316 KiB
9Accepted2/21ms316 KiB
10Accepted2/24ms564 KiB
11Accepted2/243ms2200 KiB
12Accepted1/146ms2268 KiB
13Accepted1/11ms316 KiB
14Accepted1/14ms756 KiB
15Accepted1/110ms1272 KiB
16Accepted1/129ms1436 KiB
17Accepted1/112ms1460 KiB
18Accepted1/18ms1456 KiB
19Accepted1/150ms3340 KiB
20Accepted1/143ms3312 KiB
21Accepted1/154ms3412 KiB
22Accepted1/119ms3544 KiB
23Accepted1/143ms2116 KiB
24Accepted1/146ms2252 KiB
25Accepted2/21ms316 KiB
26Accepted2/24ms568 KiB
27Accepted2/232ms1840 KiB
28Accepted1/132ms1888 KiB
29Accepted2/28ms1332 KiB
30Accepted1/129ms2336 KiB
31Accepted1/117ms2224 KiB
32Accepted2/22ms316 KiB
33Accepted2/230ms2224 KiB
34Accepted1/132ms2224 KiB
35Accepted2/234ms2180 KiB
36Accepted2/229ms2224 KiB
37Accepted2/230ms2224 KiB
38Accepted2/229ms2220 KiB
39Accepted1/12ms316 KiB