155602025-02-20 12:42:50xxxMaximális szorzat (50 pont)cpp17Wrong answer 43/5046ms2376 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()) {
        int ans = 1;
        for(int i = 0; i < negc; i++) {
            ans *= negv[i];
            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
base43/50
1Accepted0/01ms316 KiB
2Accepted0/01ms316 KiB
3Accepted0/01ms316 KiB
4Accepted0/01ms316 KiB
5Accepted0/04ms564 KiB
6Accepted2/21ms316 KiB
7Accepted2/21ms332 KiB
8Accepted2/21ms388 KiB
9Accepted2/21ms316 KiB
10Accepted2/24ms564 KiB
11Accepted2/243ms2360 KiB
12Accepted1/146ms2152 KiB
13Accepted1/11ms316 KiB
14Accepted1/14ms564 KiB
15Accepted1/110ms1308 KiB
16Accepted1/128ms1456 KiB
17Accepted1/112ms1412 KiB
18Accepted1/17ms1460 KiB
19Wrong answer0/126ms2216 KiB
20Wrong answer0/120ms2224 KiB
21Wrong answer0/132ms2224 KiB
22Wrong answer0/117ms2208 KiB
23Accepted1/143ms2124 KiB
24Accepted1/146ms2256 KiB
25Accepted2/21ms316 KiB
26Accepted2/24ms604 KiB
27Wrong answer0/216ms1460 KiB
28Wrong answer0/116ms1456 KiB
29Accepted2/28ms1524 KiB
30Accepted1/132ms2320 KiB
31Accepted1/117ms2328 KiB
32Accepted2/22ms316 KiB
33Accepted2/232ms2376 KiB
34Accepted1/132ms2232 KiB
35Accepted2/235ms2224 KiB
36Accepted2/230ms2224 KiB
37Accepted2/230ms2376 KiB
38Accepted2/230ms2356 KiB
39Accepted1/12ms316 KiB