116552024-11-03 17:18:24MagyarKendeSZLGMaximális szorzat (50 pont)cpp17Wrong answer 43/5076ms2824 KiB
#include <algorithm>
#include <cassert>
#include <iostream>
#include <queue>
#include <vector>

using namespace std;
using ll = long long;

const ll MOD = 1e9 + 7;

int main() {
    ll N, K, B;
    cin >> N >> K >> B;

    vector<ll> neg, pos;
    for (int i = 0; i < N; i++) {
        ll x;
        cin >> x;
        if (x < 0) {
            neg.push_back(x);
        } else {
            pos.push_back(x);
        }
    }

    if (neg.size() < B) {
        cout << "-1\n";
        exit(0);
    }

    sort(neg.rbegin(), neg.rend());
    ll result = 1;
    for (int i = 0; i < B; i++) {
        result *= -neg.back();
        result %= MOD;
        neg.pop_back();
    }

    priority_queue<ll, vector<ll>, greater<ll>> pq;
    for (int i = 0; i < pos.size(); i++) {
        pq.push(pos[i]);
    }
    for (int i = 0; i < neg.size(); i++) {
        pq.push(neg[i]);
    }

    if (!pq.empty()) {
        for (int i = 0; i < K; i++) {
            ll mn = pq.top();
            pq.pop();
            pq.push(mn + 1);
        }

        if (pq.top() < 0) {
            cout << "-1\n";
            exit(0);
        }

        while (!pq.empty()) {
            ll mn = pq.top();
            pq.pop();
            result *= mn;
            result %= MOD;
        }
    }

    cout << result << "\n";
}

SubtaskSumTestVerdictTimeMemory
base43/50
1Accepted0/01ms320 KiB
2Accepted0/01ms508 KiB
3Accepted0/01ms508 KiB
4Accepted0/01ms320 KiB
5Accepted0/04ms568 KiB
6Accepted2/21ms320 KiB
7Accepted2/21ms320 KiB
8Accepted2/21ms320 KiB
9Accepted2/21ms320 KiB
10Accepted2/27ms704 KiB
11Accepted2/271ms2640 KiB
12Accepted1/176ms2556 KiB
13Accepted1/12ms320 KiB
14Accepted1/17ms380 KiB
15Accepted1/130ms1036 KiB
16Accepted1/137ms1256 KiB
17Accepted1/132ms948 KiB
18Accepted1/112ms1452 KiB
19Wrong answer0/143ms1448 KiB
20Wrong answer0/132ms1456 KiB
21Wrong answer0/161ms1564 KiB
22Wrong answer0/126ms1372 KiB
23Accepted1/175ms1860 KiB
24Accepted1/176ms2824 KiB
25Accepted2/21ms320 KiB
26Accepted2/24ms568 KiB
27Wrong answer0/230ms1036 KiB
28Wrong answer0/130ms1044 KiB
29Accepted2/218ms1020 KiB
30Accepted1/163ms1492 KiB
31Accepted1/137ms2500 KiB
32Accepted2/23ms320 KiB
33Accepted2/261ms1456 KiB
34Accepted1/164ms1516 KiB
35Accepted2/265ms1544 KiB
36Accepted2/261ms1500 KiB
37Accepted2/263ms1456 KiB
38Accepted2/261ms1404 KiB
39Accepted1/12ms320 KiB