155542025-02-20 12:28:25xxxMaximális szorzat (50 pont)cpp17Runtime error 43/5046ms2404 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);
            }
        }
    }

    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/21ms316 KiB
8Accepted2/21ms316 KiB
9Accepted2/21ms316 KiB
10Accepted2/24ms564 KiB
11Accepted2/241ms2224 KiB
12Accepted1/145ms2260 KiB
13Accepted1/11ms316 KiB
14Accepted1/14ms564 KiB
15Accepted1/19ms1260 KiB
16Accepted1/127ms1456 KiB
17Accepted1/112ms1460 KiB
18Accepted1/17ms1460 KiB
19Runtime error0/123ms2200 KiB
20Runtime error0/117ms2136 KiB
21Runtime error0/128ms2248 KiB
22Runtime error0/113ms2224 KiB
23Accepted1/143ms2116 KiB
24Accepted1/146ms2252 KiB
25Accepted2/21ms316 KiB
26Accepted2/23ms564 KiB
27Runtime error0/214ms1452 KiB
28Runtime error0/114ms1356 KiB
29Accepted2/28ms1524 KiB
30Accepted1/128ms2224 KiB
31Accepted1/116ms2388 KiB
32Accepted2/22ms316 KiB
33Accepted2/229ms2304 KiB
34Accepted1/130ms2248 KiB
35Accepted2/232ms2404 KiB
36Accepted2/228ms2228 KiB
37Accepted2/228ms2224 KiB
38Accepted2/228ms2224 KiB
39Accepted1/12ms316 KiB